Archive for the ‘ZF’ category

Zend Framework (>=1.8) Step By Step

January 18th, 2010

Index:

  • environment set-up: eclipse / pdt / xDebug
  • quick start: zend.com / akrabat.com
  • zend application
  • db
  • auth / acl
  • router
  • session
  • module
  • ajax
  • cache
  • captcha / file
  • mail
  • test
  • performance
  • server clusters

Books and references:

Zend_Session_SaveHandler_DbTable doen’t work

January 15th, 2010

My current ZF version is 1.9.4. However, because my application started from 1.7.x, I wrote all bootstrap code in index.php. So we config Zend_Session_SaveHandler_DbTable like this as the document said in index.php:

$config = array(
‘name’                 => ‘session’,
‘primary’              => ‘id’,
‘modifiedColumn’  => ‘modified’,
‘dataColumn’        => ‘data’,
‘lifetimeColumn’    => ‘lifetime’
);
$saveHandler = new Zend_Session_SaveHandler_DbTable($config);
Zend_Session::setSaveHandler($saveHandler);
Zend_Session::start();

And in indexAction of IndexController, I tried to test it like this:

$session = new Zend_Session_Namespace();
$session->name = “newsbag”;

But nothing happened. There was no data inserted into the session table.

But later, I create a totally new blank project following the Quick Start of ZF & Tutorial: Getting Started with Zend Framework 1.9, it worked!

Still trying to figure out what the problem…

========== update 1 ============

Now the problem seems to be caused by the Zend_Controller_Front instance in index.php. Because when I tried to add self-defined routers in index.php in the blank project mentioned above like this:

// ROUTER
require_once ‘Zend/Controller/Router/Route.php’;
$config = new Zend_Config_Ini (‘../configs.application.ini’, ‘routers’);
$router = new Zend_Controller_Router_Rewrite();
$router->addConfig($config->routes);
$frontController->getRouter()->addRoutes($router->getRoutes());

the Zend_Session_SaveHandler_DbTable refused to work.

So DON”T instance Zend_Controller_Front in index.php.

BTW, the possible way to set routers in ZF (>= 1.8.0) would be in Bootstrap.php:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
function _initRouter(array $options = null) {
$frontController = $this->getResource(‘FrontController’);
$config = new Zend_Config_Ini (‘../application/configs/application.ini’, ‘routers’);
$router = new Zend_Controller_Router_Rewrite();
$router->addConfig($config->routes);
$frontController->getRouter()->addRoutes($router->getRoutes());
}
}