Include ZendX in Zend Framework

In: Development|How to|Zend Framework

July 04th, 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/download/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.

Written by

Dejan is pragmatic software developer with Master's Degree in Computer Science. He is currently based in Belgrade (Serbia).

  • http://twitter.com/runnerjogi Big Sunny Walker

     ZendX #zendframework

  • HideksYS

    thanx a lot

  • Etafol

    Really superb tutorial. Works like magic!

  • Carlos_sj

    descargue la ultima versión de zend y no viene zendx…!!! o estoy perdido o de plano algo pasa… mea poyan……

  • Carlos_sj

    descargue la ultima version de Zend y zendx no Viene …!!! o Estoy Perdido o de plano algo pasa …. saludos

  • Carlos_sj

    zendx not find the library and Zend download server in its final version and do not come thislibrary

  • Kgatjens

    Gracias.

  • Efrasoft

    para Carlos_sj descarga la version completa y dentro hay una carpeta llamada extras