本文整理汇总了PHP中AssetModel::viewExtensions方法的典型用法代码示例。如果您正苦于以下问题:PHP AssetModel::viewExtensions方法的具体用法?PHP AssetModel::viewExtensions怎么用?PHP AssetModel::viewExtensions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AssetModel
的用法示例。
在下文中一共展示了AssetModel::viewExtensions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: viewLocation
/**
* Get the path to a view.
*
* @param string $view the name of the view.
* @param string $controller the name of the controller invoking the view or blank.
* @param string $folder the application folder or plugins/<plugin> folder.
* @param array|null $extensions optional. list of extensions to allow
* @return string|false The path to the view or false if it wasn't found.
*/
public static function viewLocation($view, $controller, $folder, $extensions = null)
{
$paths = [];
// If the first character is a forward slash, this is an absolute path
if (strpos($view, '/') === 0) {
// This is a path to the view from the root.
$paths[] = $view;
} else {
$view = strtolower($view);
// Trim "controller" from the end of controller name, if its there
$controller = strtolower(stringEndsWith($controller, 'Controller', true, true));
if ($controller) {
$controller = '/' . $controller;
}
// Get list of permitted view extensions
if (is_null($extensions)) {
$extensions = AssetModel::viewExtensions();
}
// 1. Gather paths from the theme, if enabled
if (Gdn::controller() instanceof Gdn_Controller) {
$theme = Gdn::controller()->Theme;
if ($theme) {
foreach ($extensions as $ext) {
$paths[] = PATH_THEMES . "/{$theme}/views{$controller}/{$view}.{$ext}";
}
}
}
// 2a. Gather paths from the plugin, if the folder is a plugin folder
if (stringBeginsWith($folder, 'plugins/')) {
// This is a plugin view.
foreach ($extensions as $ext) {
$paths[] = PATH_ROOT . "/{$folder}/views{$controller}/{$view}.{$ext}";
}
// 2b. Gather paths from the application as a fallback
} else {
// This is an application view.
$folder = strtolower($folder);
foreach ($extensions as $ext) {
$paths[] = PATH_APPLICATIONS . "/{$folder}/views{$controller}/{$view}.{$ext}";
}
if ($folder != 'dashboard' && stringEndsWith($view, '.master')) {
// This is a master view that can always fall back to the dashboard.
foreach ($extensions as $ext) {
$paths[] = PATH_APPLICATIONS . "/dashboard/views{$controller}/{$view}.{$ext}";
}
}
}
}
// Now let's search the paths for the view.
foreach ($paths as $path) {
if (file_exists($path)) {
return $path;
}
}
trace(['view' => $view, 'controller' => $controller, 'folder' => $folder], 'View');
trace($paths, __METHOD__);
return false;
}