Zend Framework migration from 0.2.0 to 0.6.0
If you want to have your ZF aplication still working after migration from 0.2.0 to 0.6.0, you should make some changes in your code. However, it's desribed in manual, but only for Zend_Controller classes. There are some tips:
- Another way of setting the rewrite base
- Add second parameter to Zend_Filter_Input contructor call
- Change constructors __construct() in action controllers to init() methods
- Extend Zend_View class
- Turn on throwing exceptions by front controller
- Add echo before $this->render() methods calls in view files
- Delete base dir from first parameter of _redirect() methods in action controllers
- Add notfound plugin to emulate noRoute method
- API change in Zend_Http_Client class
1. Another way of setting the rewrite base
Change the way of setting rewrite base. Now we can do it in front controller, instead of setting this up in router. This is old way:
-
<?php
-
$router->setRewriteBase($appPath);
-
?>
and now this should be:
-
<?php
-
$frontcontroller->setBaseUrl($appPath);
-
?>
2. Add second parameter to Zend_Filter_Input contructor call
If you create instances od Zend_Filter_Input objects, make sure that the array isn't cleaned after that. You can achieve this by adding second parameter to constructors call. Instead of:
-
<?php
-
$get = new Zend_Filter_Input($_GET);
-
?>
there should be:
-
<?php
-
$get = new Zend_Filter_Input($_GET, false);
-
?>
3. Change constructors __construct() in action controllers to init() methods
If you are using constructors in action coontrollers you should change them to init() methods. Intead of:
-
<?php
-
class ArticleController extends Zend_Controller_Action
-
{
-
public function __construct()
-
{
-
// [...]
-
}
-
// [...]
-
}
-
?>
there should be:
-
<?php
-
class ArticleController extends Zend_Controller_Action
-
{
-
public function init()
-
{
-
// [...]
-
}
-
// [...]
-
}
-
?>
4. Extend Zend_View class
If you want to avoid notices informing about undefined variables you should create own view class and override offsetGet() method of ArrayObject. Our extended class should look like this:
-
<?php
-
-
class Foo_View extends Zend_View_Abstract
-
{
-
-
protected function _run()
-
{
-
}
-
-
public function offsetGet($index)
-
{
-
if (! $this->offsetExists($index)) {
-
return null;
-
}
-
return parent::offsetGet($index);
-
}
-
-
}
-
?>
Naturally, you should create instance of your new class instead of creating Zend_View instance.
5. Turn on throwing exceptions by front controller
If you want to throw exceptions in front controller you should set in in front controller, before dispatching:
-
<?php
-
$controller->throwExceptions(true);
-
?>
6. Add echo before $this->render() methods calls in view files
In view files you should echo returns of render methods. So instead of:
-
<?php
-
$this->render('foo.tpl');
-
?>
there should be:
-
<?php
-
?>
7. Delete base dir from first parameter of _redirect() methods in action controllers
If you are using _redirect() method with redirection adress containing rewrite base, you should delete rewrite base because now it's added automatically. If you were creating redirection like this:
-
<?php
-
$this->_redirect('/admin/article/index/');
-
?>
Now you should:
-
<?php
-
$this->_redirect('article/index/');
-
?>
Rewrite base (in this case "/admin/") will be prepended to redirection adress.
8. Add notfound plugin to emulate noRoute method
If you want to have noRoute method still working in 0.6.0 you should register plugin in front controller:
-
<?php
-
-
class Foo_Controller_Plugin_Notfound extends Zend_Controller_Plugin_Abstract
-
{
-
-
public function preDispatch($request)
-
{
-
$dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
-
-
if (!$dispatcher->isDispatchable($request))
-
{
-
$request->setControllerName($dispatcher->getDefaultController())
-
->setActionName('noroute')
-
->setDispatched(false);
-
}
-
}
-
-
}
-
?>
9. API change in Zend_Http_Client class
Now you should pass url to Zend_Http_Client constructor:
-
<?php
-
$http = new Zend_Http_Client('http://example.org/');
-
?>
Next add http headers:
-
<?php
-
'Accept' => 'text/html',
-
'Referer' => 'http://cms.naruniec.info',
-
'User-Agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
-
);
-
$http->setHeaders($headers);
-
?>
and finally get the GET response:
-
<?php
-
$httpResponse = $http->request();
-
?>
Before 0.6.0 we could pass headers to constructor, and we could get a GET response calling $http->get() method.
Theese tips should help in migration in most essential cases. More informations you can find in manual in chapter about Migrating from 0.2.0 or before to 0.6.0


