2010年1月22日星期五

Re: [fw-mvc] difference between coding in index.php & bootstrap.php

The advantage of moving your db initialization code into a bootstrap file is that you can reuse the bootstrap for different contexts. For example, your index.php page, which is for the web, should include the bootstrap and then dispatch the front controller.

Other scripts, such as a CLI script, would include the bootstrap and then do whatever it needs to do (which usually doesn't involve dispatching the front controller).

--
Hector


On Fri, Jan 22, 2010 at 11:35 AM, sina miandashti <miandashti@gmail.com> wrote:
hi

i create the $db object by this code in my root index.php :
/*
 * DB instance
 */
$dbConfig = $config->get ( 'db' )->toArray ();

$db = Zend_Db::factory ( $dbConfig ['adapter'], $dbConfig ['db'] );

try {
    $db->query("SET NAMES 'utf8'");
   
} catch ( Zend_Exception $e ) {
    die ( $e->getMessage () );
}
/*
 * add stuff to registery
 */

//Zend_Registry::set('templateEngine',$templateEngine);
Zend_Registry::set ( 'db', $db );
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$db->getProfiler()->setEnabled(true);

but
i saw lot of example  that doing this in bootstrap.php

what choice is better between this 2 methods of declaring main objects like $db $cache $debug and ...?

what is the difference between using these file ?

--
________________
Sincerely
Sina Miandashti
MuSicBasE.ir & InvisionPower.ir Admin

没有评论: