【发布时间】:2010-01-26 09:44:00
【问题描述】:
关于 Zend Framework 1.9 基础的几个问题。
-
我遵循了快速入门指南,基本上,引导涉及到,
一个。来自 index.php:
$ZEND_FRAMEWORK_LIB_PATH = '/appl/ZendFramework-1.9.7/library'; defined('APPLICATION_PATH') || define('APPLICATION_PATH', (realpath(dirname(__FILE__) . '/../application'))); defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); set_include_path(implode(PATH_SEPARATOR, array((dirname(dirname(__FILE__)) . '/library'), $ZEND_FRAMEWORK_LIB_PATH, get_include_path(),))); require_once 'Zend/Application.php'; $application = new Zend_Application(APPLICATION_ENV, (APPLICATION_PATH . '/configs/application.ini')); $application->bootstrap()->run();b.然后在 Bootstrap.php 中,我有
protected function _initAutoload() { $autoloader = new Zend_Application_Module_Autoloader(array("namespace" => "Default_", "basePath" => dirname(__FILE__),)); return $autoloader; } protected function _initDoctype() { $this->bootstrap("view"); $view = $this->getResource("view"); $view->doctype("XHTML1_STRICT"); } -
首先,有几件事我不明白:
一个。如果用户不是通过默认的 index.php 访问站点,这是否意味着引导(实际上,index.php 中的所有代码,包括环境设置等,都将被绕过?)
b.没有明确调用 Bootstrap 的
_initAutoload()或_initDoctype()方法的地方。那么这些方法是什么时候隐式调用的呢?c。由于在 index.php 中,我已经将配置文件
'/configs/application.ini'“传递”到 Zend_Application 构造函数,有没有办法在其他地方检索配置条目? -
在我的应用程序中,我必须使用不同的数据库(所以我不能只使用
resources.db.*)。所以在同一个 application.ini 文件中,我有,例如custdb.adapter = "PDO_MYSQL" custdb.params.host = "localhost" custdb.params.username = "username" custdb.params.password = "password" custdb.params.dbname = "custdb"管理数据库适配器的最佳做法是什么?
一个。是否可以(并且应该)在 index.php 或 Bootstrap.php 中创建数据库适配器,并在需要时(以及如何)在其他地方检索它?
b.或者是否可以(并且应该)只在其他地方检索配置条目(如何?)并在需要时实例化 DB 适配器?
谢谢!
【问题讨论】:
标签: php zend-framework