0

Zend Framework version 1.10.0 and File Decorator

10 minutes ago I downloaded Zend Framework’s latest version 1.10.0. I was using 1.7.8 for developing open source bug tracking application.
I was already aware of the change made to autoloader, but I didn’t make auotloader work for me in the first attempt. I was unable to load my models and forms.
I was using the following code for autoloading my models, forms and zend framework components.

require_once "Zend/Loader.php";
Zend_Loader::registerAutoload();

and then setting my include path as

set_include_path(
      APPLICATION_PATH . '../../../library'
    . PATH_SEPARATOR . APPLICATION_PATH . '/../application/models'
    . PATH_SEPARATOR . APPLICATION_PATH . '/../application/forms'
	. PATH_SEPARATOR . get_include_path()
);

When I replace loader code with the following code

require_once "Zend/Loader/Autoloader.php";
$autoloader = Zend_Loader_Autoloader::getInstance();

I encounter an exception saying that loader is unable to load my models. Googling for a bit of time I found the solution.
Actually Zend_Loader_Autoloader is a namespace-based autoloader. By default, it only registers the Zend_ and ZendX_ namespaces.
so it won’t load classes from your own directories.
To force loader to load your classes you will need to write the following statement right after the initialization of your loader.

$autoloader->setFallbackAutoloader(true);

Including this statment will not only load your model, but also pear packages if used in your code. I wonder you wont be able to use pear packages without writting this statement.

Another exception that I wasn’t expecting was file decorator exception. I’m using Zend_From_File for uplaoding files. As soon as I browse my page using Zend_From_File component, i was told that i am not uisng file decorator, I was setting decorator to my file element as

$file1->setDecorators(array(
			'viewHelper',
			array('Description', array('tag'=>'', 'escape'=>false)),
			array(array('data'=>'HtmlTag'),
			array('tag'=>'td', 'valign'=>'top', 'style'=> 'background-color:#ffffff;text-align:left')),
			array('Label', array('tag'=>'td')),
			array(array('row'=>'HtmlTag'), array('tag'=>'tr'))
		));

After googling my issue I found that I will need to enclude Zend_Form_Decorator_File with file elements. The changes I made are

$file1->setDecorators(array(
			'File',
			array('Description', array('tag'=>'', 'escape'=>false)),
			array(array('data'=>'HtmlTag'),
			array('tag'=>'td', 'valign'=>'top', 'style'=> 'background-color:#ffffff;text-align:left')),
			array('Label', array('tag'=>'td')),
			array(array('row'=>'HtmlTag'), array('tag'=>'tr'))
		));

By comparing the codes above you will find that I have only replaced “viewHelper” with “File”.

Filed in: Uncategorized Tags: 

Leave a Reply

Submit Comment

© 7509 Faheem Abbas. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
Top Footer