本文整理汇总了PHP中FileHelper::localize方法的典型用法代码示例。如果您正苦于以下问题:PHP FileHelper::localize方法的具体用法?PHP FileHelper::localize怎么用?PHP FileHelper::localize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHelper
的用法示例。
在下文中一共展示了FileHelper::localize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* Loads the view with the specified name.
* @param string $name The view name.
* @return string The view contents.
* @throws InvalidCallException Unable to locate the view file.
*/
public function load($name) : string
{
if (!isset($this->views[$name])) {
$viewRenderer = $this->getViewRenderer();
$cacheId = $viewRenderer->getCacheId();
$cache = mb_strlen($cacheId) ? \Yii::$app->get($cacheId) : null;
$cacheKey = static::CACHE_KEY_PREFIX . ":{$name}";
if ($cache && $cache->exists($cacheKey)) {
$output = $cache[$cacheKey];
} else {
$path = FileHelper::localize($this->findViewFile($name));
if (!is_file($path)) {
throw new InvalidCallException("The view file \"{$path}\" does not exist.");
}
$output = @file_get_contents($path);
if ($cache) {
$cache->set($cacheKey, $output, $viewRenderer->getCachingDuration());
}
}
$this->views[$name] = $output;
}
return $this->views[$name];
}
示例2: render
/**
* Renders a view file.
* @param \yii\base\View $view The view object used for rendering the file.
* @param string $file The view file.
* @param array $params The parameters to be passed to the view file.
* @return string The rendering result.
* @throws InvalidCallException The specified view file is not found.
*/
public function render($view, $file, $params) : string
{
$cacheId = $this->getCacheId();
$cache = mb_strlen($cacheId) ? \Yii::$app->get($cacheId) : null;
$cacheKey = static::CACHE_KEY_PREFIX . ":{$file}";
if ($cache && $cache->exists($cacheKey)) {
$output = $cache[$cacheKey];
} else {
$path = FileHelper::localize($file);
if (!is_file($path)) {
throw new InvalidCallException("View file \"{$file}\" does not exist.");
}
$output = @file_get_contents($path);
if ($cache) {
$cache->set($cacheKey, $output, $this->getCachingDuration());
}
}
$values = ArrayHelper::merge(['this' => $view], is_array($params) ? $params : []);
return $this->engine->render($output, $values);
}