本文整理汇总了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());
}
}