How does Zend Application / Bootstrapping work?

A few questions regarding the basics of Zend Framework 1.9.

  • I followed the quick start guide, and basically, at boot time,

    a. from 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. Then in Bootstrap.php I have

    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");
    }
    
  • To start, a few things that I don’t understand:

    a. If the user accesses the site not through the default index.php index, does this mean that the download is loading (and, indeed, all the code in index.php, including setting up the environment, etc., will bypass?)

    b. There is no place that explicitly calls Bootstrap _initAutoload()or methods _initDoctype(). So, when are these methods implicitly called?

    from. Since in index.php I already "passed" the configuration file '/configs/application.ini'to the Zend_Application constructor, is there a way to get configuration entries elsewhere?

  • ( 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 , ( )?

    . ( ) (?) ?

!

+5
3

.

2. index.php. mod_rewrite .htaccess.

2b. _init. . Zend Framework -

2. . Zend:: Config. Zend::Registry . :

$config = new Zend_Config((APPLICATION_PATH . '/configs/application.ini')); 
$application = new Zend_Application(APPLICATION_ENV, $config);
Zend_Registry::set('config', $config);

API, .

, - . . " - Zend Framework 1.8" .

+7

3, ZF Resource Resource Zend_Application_Resource_Db .

, DB application.ini.

[production]
resources.db.adapter = PDO_MYSQL
resources.db.params.host = localhost
resources.db.params.username = user
resources.db.params.password = pass
resources.db.params.dbname = production_db

[staging : production]
resources.db.params.dbname = staging_db

[development : production]
resources.db.params.dbname = development_db

[production] . , .htaccess

, .

, . Zend_Application_Resource_ResourceAbstract. , resources.* , :

$this->getBootstrap()-getResource('mydb')`

:

$bootstrap->getPluginResource('mydb')

, .

EDIT: , .ini, Zend_Application , , - _init() . - .

, , , , Zend_Registry.

+2

! ZF.

, , , :

application.ini :

custom.db.customers.adapter = "PDO_MYSQL"
custom.db.customers.params.host = "localhost"
custom.db.customers.params.username = "username"
custom.db.customers.params.password = "password"
custom.db.customers.params.dbname = "custdb"

Bootstrap.php :

protected function _initCustomDbCustomers()
{
    $config = $this->getOptions();
    $cfgCustom = $config['custom'];
    if (null != $cfgCustom)
    {
        $cfgCustomDb = $cfgCustom['db'];
        if (null != $cfgCustomDb)
        {
            $cfgCustomDbCustomers = $cfgCustom['customers'];
            if (null != $cfgCustomDbCustomers)
            {
                $resrcCustomDbCustomers = new Zend_Application_Resource_Db($cfgCustomDbCustomers);
                return $resrcCustomDbCustomers
            }
        }
    }
}

, index.php :

$application->bootstrap();
$application->run();

, DB, :

$bootstrap = $this->getInvokeArg('bootstrap');
$resrcCustomDbCustomers = $bootstrap->getResource('customDbCustomers');
$adpCustomDbCustomers = $resrcCustomDbCustomers->getDbAdapter();
// Do Stuffs With DB Adapter

/ -? - , ?

!

0

All Articles