Zend Framework

De Bricosoft.

Sommaire

[modifier] Eclipse / Zend Studio

[modifier] Eclipse suggestion de code

Il faut avoir au préalable téléchargé la version de ZF dans un coin :

cd ~/libs/
svn checkout http://framework.zend.com/svn/framework/standard/trunk zend

Bouton droit sur le projet puis Properties :

PHP Include Path > Add Library > Config > New > User Library Name : ZF ...

Ensuite indiquez le chemin vers ... ~/libs/zend/ ou ton chemin banane !

Bon fais comme dans l'infanterie : tu te casses ailleurs !

[modifier] ZendX_Jquery

[modifier] Installation

Installer la bibliothèque ZendX (pas livrée avec le Zend Framework mais maintenue au même endroit)

$ pwd
/home/gbp4dt5/libs/zend/library
$ ls
Zend

Récuperer ZendX

svn co http://framework.zend.com/svn/framework/extras/trunk/library/ZendX/

$ tree -d -L 2 .

.
|-- Zend
|   |-- Acl
...
|   `-- XmlRpc
`-- ZendX
    |-- Application
    |-- Console
    |-- Db
    `-- JQuery

C'est installé au même niveau et non dans Zend/. Pour votre information la librairie Dojo est dedans car officiellement supportée.

[modifier] Code d'exemple

Dans le bootstrap (application/Bootstrap.php) :

	protected function _initViewHelpers() {
		$this->bootstrap ( 'view' );
		$view = $this->getResource ( 'view' );
		$view->addHelperPath ( "ZendX/JQuery/View/Helper", "ZendX_JQuery_View_Helper" );
		$view->jQuery()->addStylesheet ( '/js/jquery/css/ui-lightness/jquery-ui-1.7.2.custom.css' )
			->setLocalPath ( '/js/jquery/js/jquery-1.3.2.min.js' )
			->setUiLocalPath ( '/js/jquery/js/jquery-ui-1.7.2.custom.min.js' );
 
		$view->headLink()->appendStylesheet( '/css/bricosoft.css' );
		$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer ( );
		$viewRenderer->setView ( $view );
		Zend_Controller_Action_HelperBroker::addHelper ( $viewRenderer );
	}

Dans le layout (application/layouts/scripts/layout.phtml) :

<?= $this->doctype ()?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>www.bricosoft.com</title>
<link rel="stylesheet" type="text/css"	href="css/grids-min.css">
<?= $this->jQuery()->enable();?>
<?= $this->headLink();?>
</head>

enable() est ici explicite dans le cas où l'on n'utilisera pas d'objets ZendX_JQuery. On peut tout aussi bien mettre $this->jQuery() si l'on est sûr d'instancier un objet ZendX_JQuery.

Premier choix dans le contrôleur en appelant directement l'objet ZendX_JQuery_Form :

    public function indexAction()
    {
		$form = new ZendX_JQuery_Form();
		$date = new ZendX_JQuery_Form_Element_DatePicker( 'date',
                        array('label' => 'La date :')
        		);
		$form->addElement($date);
		$this->view->form = $form;
    }

Soit en créant votre objet (c'est plus élégant) à placer dans library/My/Forms/Totoche.php

Remplacez alors dans le contrôleur :

$form = new ZendX_JQuery_Form();

par :

$form = new My_Forms_Totoche();

Votre objet :

class My_Forms_Totoche extends ZendX_JQuery_Form
{
	public function init()
	{
		$this->setName('Totoche');
		$date = new ZendX_JQuery_Form_Element_DatePicker( 'date');
		$this->addElement($date);
...

Après ce choix cornélien, il reste la Vue :

<?php 
echo $this->form;
?>

Et voilà, un clic sur l'élement affiche un calendrier sexy.

Plus