索引和application.ini混淆&几个简单的问题


index and application.ini confusion & few simple questions

Zend框架新功能。我一直在阅读,发现application.ini中提到的任何内容都是初始化的。

1 -我的问题是如果我在ini中提到了库的包含路径,那么为什么我需要在索引文件中再次使用包含路径,如

// Include path
set_include_path(
    BASE_PATH . '/library'
);

2 -在application.ini我应该写includePaths。像APPLICATION_PATH "/../library"或APPLICATION_PATH "/library"。还记得我的索引APPLICATION_PATH变量吗?

3 -为什么我要在启动文件中_initView()。像

这样的代码有什么用?
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
                'ViewRenderer'
            );
            $viewRenderer->setView($view); 

application.ini提到

;Include path
includePaths.library = APPLICATION_PATH "/../library"

引导

<?php
    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
    {
        protected function _initView()
        {
            // Initialize view
            $view = new Zend_View();
            $view->doctype('XHTML1_STRICT');
            $view->headTitle('My Project');
            $view->env = APPLICATION_ENV;
            // Add it to the ViewRenderer
            $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
                'ViewRenderer'
            );
            $viewRenderer->setView($view);
            // Return it, so that it can be stored by the bootstrap
            return $view;
        }
    }

<?php
define('BASE_PATH', realpath(dirname(__FILE__) . '/../'));
define('APPLICATION_PATH', BASE_PATH . '/application');
// Include path
set_include_path(
    BASE_PATH . '/library'
);
// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV',
              (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV')
                                         : 'production'));
// Zend_Application
require_once 'Zend/Application.php';
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap();
$application->run();

1和2是旧版本Zend Framework遗留下来的冗余。一般来说,你可以选择一种方法并坚持下去。

index.php

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

application.ini

includePaths.library = APPLICATION_PATH "/../library"

我个人倾向于前者。

你的Bootstrap.php文件似乎也有一些旧的ZF习惯。较新的应用程序体系结构包括用于视图的资源插件。只需将其放入application.ini文件

resources.view.encoding = "utf-8"
并将bootstrap方法更改为
// don't call this _initView as that would overwrite the resource plugin
// of the same name
protected function _initViewHelpers()
{
    $this->bootstrap('view'); // ensure view resource has been configured
    $view = $this->getResource('view');
    $view->doctype('XHTML1_STRICT');
    $view->headTitle('My Project');
    $view->env = APPLICATION_ENV;
}