2011-09-05 59 views
2

Zend Framework的新功能。我一直在閱讀,發現無論在application.ini中提到什麼都被初始化。索引和application.ini混淆和一些簡單的問題

1 - 我的問題是,如果我提到包括圖書館比我爲什麼需要使用INI路徑一樣

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

2索引文件又包含路徑 - 中的application.ini應我寫了像APPLICATION_PATH「/../library」或APPLICATION_PATH「/ library」的includePaths.library。請記住我的索引APPLICATION_PATH變量?

3 -爲什麼要在BootStarp文件中使用_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(); 

回答

3

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" 

,改變你的引導方法

// 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; 
} 
+0

你喜歡INI圖書館和初始化。對? – Pirzada

+0

爲了設置包含路徑,我更喜歡在index.php中使用代碼。所有其他配置都在應用程序配置文件中 – Phil