如何消除views / scripts文件夹?

时间:2010-01-13 18:30:25

标签: php zend-framework views

假设我已经厌倦了将我的页面模板文件夹放在视图/脚本下,并希望将它们放在视图下,而忽略了路径中的“脚本”部分。如何更改ZendFramework的配置以允许我这样做?

2 个答案:

答案 0 :(得分:2)

尝试以下方法:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

// ...

    protected function _initView()
    {
        // Initialise the view
        $view = new Zend_View();
        $view->addScriptPath(APPLICATION_PATH.'/views');

        // set the configured view as the view to be used by the view renderer.
        $renderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
        $renderer->setView($view);

        return $view;
    }

// ...

}

上一个答案缺少您设置视图的部分,该视图已配置为具有View View Renderer的附加脚本路径。

HTH。

答案 1 :(得分:1)

请参阅ZF Manual for Zend_View并将其放入引导程序中:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initView()
    {
        $view = new Zend_View();
        $view->setScriptPath('/some/new/path');   // overwrite any paths
        $view->addScriptPath('/some/other/path'); // adds additional paths
        $view->setEncoding('UTF-8');
        $view->doctype('XHTML1_STRICT');
        $view->headMeta()->appendHttpEquiv(
            'Content-Type', 'text/html;charset=utf-8'
        );
        $viewRenderer =
        Zend_Controller_Action_HelperBroker::getStaticHelper(
            'ViewRenderer'
        );
        $viewRenderer->setView($view);
        return $view;
    }
}

configure your Ini for use with Zend_Application_Resource_View

resources.view.encoding = "UTF-8"
resources.view.basePath = APPLICATION_PATH "/views/scripts"
...

请注意,所选的basePath假定目录结构为:

base/path/
    helpers/
    filters/
    scripts/

另见tutorial by Padraic Brady