I am migrate for a new version of zend framework... but I have some problems with bootstrap.
Is ok this bootstrap:
<?php
/**
* Application bootstrap
*
* @uses Zend_Application_Bootstrap_Bootstrap
* @package QuickStart
*/
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
public static $frontController = null;
public static $root = '';
public static $registry = null;
/**
* Bootstrap autoloader for application resources
*
* @return Zend_Application_Module_Autoloader
*/
protected function _initAutoload()
{
$autoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Default',
'basePath' => dirname(__FILE__),
));
return $autoloader;
}
/**
* Bootstrap the view doctype
*
* @return void
*/
protected function _initDoctype()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype('XHTML1_STRICT');
}
public static function _initPrepare()
{
self::setupRegistry();
self::setupConfiguration();
self::setupFrontController();
self::setupView();
self::setupLogger();
self::setupDatabase();
self::setupSession();
}
// Date time setting will be done here
public static function setupDateTime()
{
date_default_timezone_set('Europe/Lisbon');
}
public static function setupRegistry()
{
self::$registry = new Zend_Registry(array(), ArrayObject::ARRAY_AS_PROPS);
Zend_Registry::setInstance(self::$registry);
}
public static function setupConfiguration()
{
$config = new Zend_Config_Ini(
APPLICATION_PATH . '/configs/application.ini', 'site');
self::$registry->configuration = $config;
}
public static function setupFrontController()
{
self::$frontController = Zend_Controller_Front::getInstance();
self::$frontController->throwExceptions(true);
self::$frontController->returnResponse(true);
self::$frontController->setControllerDirectory(
array(
'Default' => APPLICATION_PATH . '/controllers',
'Admin' => APPLICATION_PATH . '/Admin/controllers'
)
);
self::$frontController->setParam('registry', self::$registry);
}
public static function setupView()
{
$view = new Zend_View;
$view->setEncoding('UTF-8');
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
Zend_Layout::startMvc(
array(
'layoutPath' => APPLICATION_PATH . '/views/layouts',
'layout' => 'layout',
'contentKey' => 'content'
)
);
}
//Logger setup will can be done using following
public static function setupLogger()
{
/**
* Create a log formatter
*/
$format = '%timestamp% %priorityName% (%priority%): %message%' . PHP_EOL;
$formatter = new Zend_Log_Formatter_Simple($format);
/**
* Create a file logger
*/
$stream = @fopen(APPLICATION_PATH . "tmp/logs/" . date("Y-m-d") . ".php", 'a', false);
if (!$stream)
{
throw new Exception('Failed to open stream');
}
try
{
$fileWriter = new Zend_Log_Writer_Stream($stream);
$fileWriter->setFormatter($formatter);
$fileLogger = new Zend_Log($fileWriter);
Zend_Registry::set("fileLogger", $fileLogger);
}
catch (Zend_Log_Exception $e)
{
echo "Error: " . $e->getMessage();
}
catch (Zend_Exception $e)
{
echo "Error: " . $e->getMessage();
}
}
public static function setupDatabase()
{
$config = self::$registry->configuration;
$db = Zend_Db::factory($config->db->adapter, $config->db->config->toArray());
$db->query("SET NAMES 'UTF8'");
$db->query("SET CHARACTER SET 'UTF8'");
self::$registry->db = $db;
Zend_Db_Table::setDefaultAdapter($db);
}
/*
Zend session setting done here.
*/
public static function setupSession()
{
try
{
Zend_Session::setOptions(array(
'save_path' => APPLICATION_PATH . "/tmp/sessions",
'remember_me_seconds' => 7200,
));
Zend_Session::start();
}
catch (Zend_Session_Exception $e)
{
$dbLogger->log('Error: ' . $e->getMessage(), 1);
$fileLogger->log($e->getMessage(), 1);
}
$defaultNs = new Zend_Session_Namespace('default');
Zend_Registry::set("defaultNs", $defaultNs);
if($config->log_level == 2)
{
$fileLogger->info();
}
}
}
If you see any problem please reply this email..
Saudações Cordiais,
Miguel Vieira
IT ANALYST
没有评论:
发表评论