[英]Change Zend Framework module view script path
Currently view scripts located in APPLICATION_PATH . '/modules/my_module/views/scripts/'
目前查看位于
APPLICATION_PATH . '/modules/my_module/views/scripts/'
脚本APPLICATION_PATH . '/modules/my_module/views/scripts/'
APPLICATION_PATH . '/modules/my_module/views/scripts/'
. APPLICATION_PATH . '/modules/my_module/views/scripts/'
。 I want to place scripts in '/modules/my_module/views/'
(remove scripts folder). 我想将脚本放在
'/modules/my_module/views/'
(删除脚本文件夹)。 How to achieve this? 怎么做到这一点?
application.ini: 的application.ini:
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =
resources.view.scriptPath.default = APPLICATION_PATH "/views"
You could use the setScriptPath(APPLICATION_PATH . '/modules/my_module/views')
view method to replace the script path. 您可以使用
setScriptPath(APPLICATION_PATH . '/modules/my_module/views')
视图方法来替换脚本路径。
You can also add your script path without overriding the previous one, using addScriptPath(APPLICATION_PATH . '/modules/my_module/views')
. 您还可以使用
addScriptPath(APPLICATION_PATH . '/modules/my_module/views')
添加脚本路径而不覆盖前一个路径。 I use it to have organized the view scripts in different folders. 我用它来组织不同文件夹中的视图脚本。
Hope that helps... 希望有帮助......
I created plugin: 我创建了插件:
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);
}
}
}
and registered it in application.ini
: 并在
application.ini
注册:
resources.frontController.plugins[] = "Application_Model_Controller_Plugin_AddScriptPath"
I know this is pretty old but it may help someone. 我知道这很古老但可能对某人有所帮助。 I had this same problem.
我有同样的问题。 I achieved this by using
我通过使用实现了这一点
resources.view.scriptPath = APPLICATION_PATH "/views/"
if you want change view script for any action 如果您想要任何操作的更改视图脚本
inside your controller action add this: 在你的控制器动作内添加:
$this->view->addScriptPath(APPLICATION_PATH . 'your/path'); $ this-> view-> addScriptPath(APPLICATION_PATH。'your / path');
$this->renderScript('list.phtml'); $这 - >的renderScript( 'list.phtml');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.