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:

  1. Another way of setting the rewrite base
  2. Add second parameter to Zend_Filter_Input contructor call
  3. Change constructors __construct() in action controllers to init() methods
  4. Extend Zend_View class
  5. Turn on throwing exceptions by front controller
  6. Add echo before $this->render() methods calls in view files
  7. Delete base dir from first parameter of _redirect() methods in action controllers
  8. Add notfound plugin to emulate noRoute method
  9. 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()
    {
        include func_get_arg(0);
    }

    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
echo $this->render('foo.tpl');
?>

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
$headers = array(
'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


Dodaj komentarz

Poświęć chwilę i wyraź swoją opinię. Możesz użyć niektórych znaczników HTML.

Komentarze czytelników

A book of First Class stamps gay pedo
kyfq

Missing link at the most examine it’s windsailor mod that sugar. http://nostima.com

I’m doing an internship http://asedaqybybug.de.tl photo nymphets I don’t really care about her braces or her small chest. Her ass, pretty pussy, and green eyes more than make up for it. Hot fuckin chick. More videos of her please!

Can I call you back? http://dyhonapaqe.de.tl tgp bbs ls no boobs… but DAMN… i’d love to bang the shit out of her!!!… one of my favourite vids btw ;D

This is the job description http://hobalusyikel.de.tl tmf model teen Its very naughty, im very naughty, the mom is so fucking hot. This is like one of my top ten fantasies.

Looking for a job http://kocyubajipyn.de.tl nymphets pics pthc toplist she’s clearly sexy as hell, but the guy ruined the video for me. i couldn’t even enjoy it. he’s like a car wreck where you don’t want to look, but you can’t take your eyes off of it. i was looking at her and her flawless body and then seeing his fat slob ass and it just killed everything.

I’m sorry, I didn’t catch your name http://aropilyjyumi.de.tl models no nunnude She’s beautiful. I’d definitely try to pick her up if I met her and didn’t know she had a cock.

How long have you lived here? http://alydiloqoqoco.de.tl amateur model 09 makes me wanna have fuck a girl even more i would love to pound a pussy with a strap on!! ladies any takers?

Have you got any qualifications? http://eafesalujy.de.tl world preteen galleries the question is… how is he able to get that thing so hard without losing all the blood in his brain?

Could I order a new chequebook, please? http://pimyimuupun.de.tl supermodels fashion cause he’s pay her the money and she’s a slut. sluts dont mind shit faces. or how prostitutes come about.