Als een vervolg op mijn vorige post op per module gebaseerd layout instellingen voor Zend Framework , ik heb update van de code te verlangen minder configuratie dan voor (niet dat het nodig is meer dan een paar regels in uw toepassing configuratie!).
Continue reading 'Zend Framework Per module Layout Instellingen - Follow Up' »
De artikelen , Computing , PHP , Programmering van het Web , Zend Framework |
actie , controller , kader , helper , lay-out , module , PHP , Zend , Zend Framework
Ik heb een follow-up op dit bericht die minder configuratie vereist gemaakt, zie Module Based Layout - Zend Framework .
Bij gebruik van de Zend Framework met modules, haar duidelijk dat als u gebruik maakt van diverse (sub-) sites buiten de dezelfde toepassing die u niet per se hetzelfde willen lay-out scripts voor elk onderdeel. Ik besloot om te gaan met de volgende site structuur:
/ Toepassing
/ Controllers
...
/ Modellen
/ Modules
/ Default
/ Controllers
/ Lay-out
/ Scripts
/ Uitzicht
/ Scripts
/ AnotherModule
...
/ Scripts
Het probleem was het opzetten van de lay-out scripts op een per-module basis. Het antwoord kwam door het gebruik van een Action Helper. Het instellen van de lay-outs op een per-module basis bestaat uit drie stappen:
- Application.ini (of soortgelijke configuratie setup):
admin.resources.layout.layoutPath = APPLICATION_PATH "/ modules / admin / layouts / scripts"
default.resources.layout.layoutPath = APPLICATION_PATH "/ modules / default / layouts / scripts"
member.resources.layout.layoutPath = APPLICATION_PATH "/ modules / member / layouts / scripts"
affiliate.resources.layout.layoutPath = APPLICATION_PATH "/ modules / affiliate / layouts / scripts"
- Maak je Actie Helper:
<? Php
/ **
* Stelt de lay-out pad op een per-module basis
*
* @ Author Lloyd Watkin <lloyd@evilprofessor.co.uk>
* @ Sinds 2010-01-01
* /
klasse Pro_Controller_Action_Helper_SetLayoutPath
breidt Zend_Controller_Action_Helper_Abstract
{
/ **
* Stelt lay-out pad op basis van module
* /
publieke functie preDispatch ()
{
Module = $ $ this-> GetRequest () -> getModuleName ();
if ($ bootstrap = $ this-> getActionController ()
-> GetInvokeArg ('bootstrap')) {
$ Config = $ bootstrap-> getOptions ();
if (isset ($ config [$ module] ['resources'] ['layout'] ['layoutPath'])) {
$ LayoutPath =
$ Config [$ module] ['resources'] ['layout'] ['layoutPath'];
$ This-> getActionController ()
-> GetHelper ('lay-out')
-> SetLayoutPath ($ layoutPath);
}
}
}
} - En tot slot boostrap de actie helper:
...
/ **
* Stelt lay-out scripts op een per-module basis
* /
beschermde functie _initLayoutHelper ()
{
$ This-> bootstrap ('frontController');
$ Layout = Zend_Controller_Action_HelperBroker:: addHelper (
nieuw Pro_Controller_Action_Helper_SetLayoutPath ());
}
...