更改Zend Framework模块视图脚本路径

And*_*nko 4 zend-framework module view path

目前查看位于的脚本APPLICATION_PATH . '/modules/my_module/views/scripts/'.我想将脚本放入'/modules/my_module/views/'(删除脚本文件夹).怎么做到这一点?

的application.ini:

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =
resources.view.scriptPath.default = APPLICATION_PATH "/views"
Run Code Online (Sandbox Code Playgroud)

din*_*pmi 6

您可以使用setScriptPath(APPLICATION_PATH . '/modules/my_module/views')view方法替换脚本路径.

您也可以使用添加脚本路径而不覆盖前一个路径addScriptPath(APPLICATION_PATH . '/modules/my_module/views').我用它来组织不同文件夹中的视图脚本.

希望有帮助......


And*_*nko 6

我创建了插件:

class Application_Model_Controller_Plugin_AddScriptPath extends Zend_Controller_Plugin_Abstract
{
    public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {
        $view = Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer')->view;
        $scriptPath = sprintf('%s/modules/%s/views',
                APPLICATION_PATH,
                $request->getModuleName());
        if (file_exists($scriptPath)) {
            $view->addScriptPath($scriptPath);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

并注册于application.ini:

resources.frontController.plugins[] = "Application_Model_Controller_Plugin_AddScriptPath"
Run Code Online (Sandbox Code Playgroud)