Include ZendX in Zend Framework

04 Jul 2011

As many of you know – ZendX stands for “Zend Framework – Extras Library”. They were introduced since Zend Framework version 1.7 and is here to help us implement alternatives to already existing solutions. I am a big fan of jQuery and therefore will explain how to include ZendX library and start using jQuery with Zend Framework – the right way.

ZendX – jQuery: First steps

To start using a ZendX, first we must:

  • download a current Zend Framework from: http://framework.zend.com/downloads/latest;
  • extract it and search for ZendX in folder library;
  • copy the whole ZendX folder to your projects library so that you get library/ZendX;

ZendX – jQuery: Bootstrap

Now that we have set ZendX library into our project – we should initialize it on Bootstrap in method _initViewHelpers. This is how we can do it:

protected function _initViewHelpers()
{
	$view = new Zend_View();
	$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
 
	$view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');
	$viewRenderer->setView($view);
	Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
}

ZendX – jQuery: The layout

This however – is not enough to start using jQuery. We should add a few more lines to site layout script. I prefer putting it to a bottom of my layout as it is good practice to set your JavaScript after HTML and before tag. To include jQuery and jQuery UI (versions 1.5.1 and 1.8.11) – we should use following lines:

echo $this->jQuery()
	->setVersion('1.5.1')
	->setUiVersion('1.8.11')
	->enable()
	->uiEnable();

By default, the jQuery library is loaded from the Google Ajax Library Content Distribution Network. I must say that this should not worry you as I have recently lost internet connection and realized that these libraries were cached in browser so I just continued my development without having change links to JS.

ZendX – jQuery: Finishing touches

We have included jQuery and jQuery UI, but we didn’t setup the CSS for jQuery UI. I believe it is best to style your own theme on jQuery UI website and download it so it can fit your websites style. To customize/make your theme visit: theme roller.

This should be the all you need to start using ZendX with jQuery in your Zend Framework project.

  • Was this helpful?
  • Yes   No
  • Back