本文整理匯總了PHP中yii\web\View::renderPhpFile方法的典型用法代碼示例。如果您正苦於以下問題:PHP View::renderPhpFile方法的具體用法?PHP View::renderPhpFile怎麽用?PHP View::renderPhpFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yii\web\View
的用法示例。
在下文中一共展示了View::renderPhpFile方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: createManifest
protected function createManifest($id, $html)
{
try {
$filename = $this->getFileName($id);
if (@file_get_contents($filename) == false) {
$caches = [];
$paths = [];
$baseUrl = Yii::getAlias('@web') . '/';
$basePath = Yii::getAlias('@webroot') . '/';
// css
$matches = [];
$pattern = '/<link [^>]*href="?([^">]+)"?/';
preg_match_all($pattern, $html, $matches);
if (isset($matches[1])) {
foreach ($matches[1] as $href) {
$caches[$href] = true;
if (($path = $this->convertUrlToPath($href, $basePath, $baseUrl)) !== false) {
$path = dirname($path);
if (!isset($paths[$path]) && is_dir($path)) {
$paths[$path] = true;
foreach (FileHelper::findFiles($path) as $file) {
$caches[$this->convertPathToUrl($file, $basePath, $baseUrl)] = true;
}
}
}
}
}
// js
$matches = [];
$pattern = '/<script [^>]*src="?([^">]+)"?/';
preg_match_all($pattern, $html, $matches);
if (isset($matches[1])) {
foreach ($matches[1] as $src) {
$caches[$src] = true;
}
}
// img
$matches = [];
$pattern = '/<img [^>]*src="?([^">]+)"?/';
preg_match_all($pattern, $html, $matches);
if (isset($matches[1])) {
foreach ($matches[1] as $src) {
if (strpos($src, 'data:') !== 0) {
$caches[$src] = true;
}
}
}
unset($caches[false]);
$data = array_keys($caches);
if ($this->rel) {
$l = strlen($baseUrl);
foreach ($data as $key => $url) {
if (strpos($url, $baseUrl) === 0) {
$data[$key] = substr($url, $l);
}
}
}
$view = new View();
$manifest = $view->renderPhpFile(Yii::getAlias('@mdm/clienttools/manifest.php'), ['caches' => array_merge($data, $this->extraCaches)]);
FileHelper::createDirectory(dirname($filename));
file_put_contents($filename, $manifest);
}
} catch (\Exception $exc) {
\Yii::error($exc->getMessage());
}
}