New to Zend Framework. I been reading and found that whatever mentioned in application.ini is initialized.
1 – My Question is if I have mentioned include path for Library in ini than why I need to use include path again in index file like
// Include path
set_include_path(
BASE_PATH . '/library'
);
2 – in application.ini should I write includePaths.library like APPLICATION_PATH “/../library” OR APPLICATION_PATH “/library”. Keeping in mind my index APPLICATION_PATH variable?
3 – Why should I _initView() in BootStarp file. What is the use of that code like
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
'ViewRenderer'
);
$viewRenderer->setView($view);
application.ini mentioned
;Include path
includePaths.library = APPLICATION_PATH "/../library"
Bootstrap
<?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;
}
}
index
<?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 and 2 are a lingering redundancy from older versions of Zend Framework. You may generally choose one method and stick to it.
Either
index.phpor
application.iniPersonally, I favour the former.
Your
Bootstrap.phpfile also seems to have a few older ZF habits. The newer application architecture includes a resource plugin for the view. Simply place this into yourapplication.inifileand change your bootstrap method to