2010-03-30 5 views
7

Actuellement, je trouve que je dois continuer à reproduire des partiels pour différents modules.Zend Framework modulaire avec une base de partials

Je voudrais avoir un répertoire de cas pour tous les partiels à accéder.

Est-ce que quelqu'un a un bon moyen de le faire?

Merci

Répondre

8
$this->partial('directoryOfPartials/partial.phtml', $model); 

Je pense que vous pouvez également utiliser $ this-> partielle avec trois arguments. Le deuxième argument est un nom de module et le troisième argument devient le modèle.

Taken From: http://framework.zend.com/manual/en/zend.view.helpers.html

Example #10 Rendering Partials in Other Modules Sometime a partial will exist in a different module. If you know the name of the module, you can pass it as the second argument to either partial() or partialLoop(), moving the $model argument to third position. For instance, if there's a pager partial you wish to use that's in the 'list' module, you could grab it as follows:

<?php echo $this->partial('pager.phtml', 'list', $pagerData) ?> 

In this way, you can re-use partials created specifically for other modules. That said, it's likely a better practice to put re-usable partials in shared view script paths.

EDIT - Accès partials vue de l'intérieur d'un périmètre d'action du contrôleur

$this->view->getHelper('partial')->partial('comments.phtml'); 
+0

Merci, ce qui est excellent pour la vue, mais je une requête à l'utiliser via le contrôleur, vous répondra dans une nouvelle poste ci-dessous pour être plus clair – azz0r

+0

quoi faire en vue lorsque vous définissez partiel dans helper? Je veux dire après cela, ce que vous avez posté après votre modification? Vous définissez partial à comments.phtml, mais que faire avec cela en vue? TIA – prostynick

2

excellent merci :)

Cependant, comment puis-je faire via le controlle? Je fancybox et ont mis en place la disposition ajax:

$this->view->layout()->setLayout('ajax'); 

$errors = array('You have lost your rights to download this clip, you have downloaded it the maximum amount of times.'); 

$this->render($this->view->partial('partials/errors.phtml', 'default', array('errors' => $errors)), NULL, true); 

La fenêtre pop-up au besoin, mais avec l'erreur suivante:

Problem: Method "partial" does not exist and was not trapped in __call() 

je suppose un peu de $ this-> view-> partielle serait le même que d'utiliser $ this-> partial dans le template de la vue, mais je suppose que non. Des idées?

SOLVED VIA:

Bootstrap initView, a ajouté:

$view->addScriptPath('../application/layouts/partials'); 

Moved My partials dans ce répertoire. Puis, dans mon contrôleur je fais:

$this->view->layout()->setLayout('ajax'); 
$this->view->form = $form; 
$this->renderScript('login.phtml'); 

Merci va à #zftalks SmartSsa

+1

$ this-> view-> getHelper ('partial') -> partial ('comments.phtml'); Je l'ai aussi ajouté à ma réponse. – Ballsacian1

Questions connexes