2010-03-30 17 views
7

Attualmente sto trovando che devo continuare a duplicare le partizioni per i diversi moduli.Modular Zend Framework con una base di partial

Vorrei avere una directory dei casi per tutti i parziali a cui accedere.

Qualcuno ha un buon modo per farlo?

Grazie

risposta

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

penso che è anche possibile utilizzare $ this-> parziale con tre argomenti. Il secondo argomento è un nome di modulo e il terzo argomento diventa il modello.

Tratto da: 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 - Accesso vista parziali dall'interno ambito di azione di un controller

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

Grazie, questo è grande per la vista, ma ho una domanda su come utilizzare tramite il controller, risponderà in una nuova postare sotto per essere più chiari – azz0r

+0

cosa fare in vista quando si imposta parziali in helper? Voglio dire, dopo quello che hai postato dopo la tua modifica? Hai impostato un partial su comments.phtml, ma cosa fare con questo in vista? TIA – prostynick

2

eccellenti grazie :)

Tuttavia, come faccio a fare questo via il controller? Ho fancybox e ho posto il layout 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 finestra pop-up, come richiesto, ma con il seguente errore:

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

ho un pò di assunse il $ this-> Visualizza-> parziale sarebbe lo stesso di usare $ this-> partial all'interno del modello di visualizzazione, ma non credo. Idee?

RISOLTO VIA:

Bootstrap initView, ha aggiunto:

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

spostato il mio parziali a quella directory. Poi, nel mio controller che faccio:

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

Grazie va a #zftalks SmartSsa

+1

$ this-> view-> getHelper ('partial') -> partial ('comments.phtml'); L'ho anche aggiunto alla mia risposta. – Ballsacian1