目前,我正在从管理员模块中选择此视图(/admin/config/users
)的URL /路由private/apps/Admin/Views/user/users.volt
上加载所有用户。
现在我已经为自定义布局设置了一个标志。因此,如果启用了自定义布局,则我希望phalcon从AdminExtension模块中选择视图,即(private/apps/Admin/Extension/Views/user/users.volt
)
我该如何实现?我要两种看法。因为private/apps/Admin/Views/user/users.volt
是列出所有用户的默认视图。但是,private/apps/Admin/Extension/Views/user/users.volt
是为客户定制的视图,在其中进行了许多设计更改。
这是调度程序代码的外观:
/**
* @param Dispatcher $dispatcher
*/
public function afterExecuteRoute(Dispatcher $dispatcher) {
// Check if Json response is required
if ($this->_isJsonResponse) {
//if body
} else {
if(CxSettingCustomLayout::loadFromDb()->isCustomLayout()) {
//pick custom view here" `private/apps/Admin/Extension/Views/user/users.volt`
}
// Build current module configuration settings section name
$moduleConfigName = 'app_' . $this->dispatcher->getModuleName();
// Include assets configuration file where assets collections are defined
if(file_exists($this->config[ $moduleConfigName ]['assetsFile']))
include $this->config[ $moduleConfigName ]['assetsFile'];
// Set a view variable with the current language code
$this->view->setVar('current_language_code', $this->CxTranslation->getLanguage()->getCode());
}
}
正如@ num8er已经说过的,请尝试使用setViewsDir
。我通过以下方式使用Phalcons Simple
视图类
use Phalcon\Mvc\View\Simple;
$view = new Simple();
$view->setViewsDir(BASE_PATH . '/app/views/');
echo $view->render('admin/users');