如何强制Phalcon从另一个模块而不是已定义的模块中选择视图?

问题描述 投票:0回答:1

目前,我正在从管理员模块中选择此视图(/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());
    }
}
model-view-controller phalcon dispatcher phalcon-orm
1个回答
0
投票

正如@ n​​um8er已经说过的,请尝试使用setViewsDir。我通过以下方式使用Phalcons Simple视图类

use Phalcon\Mvc\View\Simple;

$view = new Simple();
$view->setViewsDir(BASE_PATH . '/app/views/');
echo $view->render('admin/users');
© www.soinside.com 2019 - 2024. All rights reserved.