Als Follow-up zu meinem vorherigen Post auf pro Modul basiertes Layout-Einstellungen für Zend Framework , ich habe den Code zu verlangen, aktualisiert weniger Konfiguration dann vor (nicht, dass es notwendig mehr als ein paar Zeilen in Ihre Applikation Konfiguration!).
Continue reading 'Zend Framework pro Modul Layout-Einstellungen - Follow Up' »
Artikel , Computing , PHP , Web-Programmierung , Zend Framework |
Aktion , Controller , Rahmen , Helfer , Layout , Modul , PHP , Zend , Zend Framework
Ich habe eine Antwort auf diese Stelle, die weniger Konfiguration erfordert erstellt, siehe Module Based Layout - Zend Framework .
Bei der Verwendung des Zend Framework mit Modulen, ist offensichtlich, dass, wenn Sie verschiedene (Sub-) Seiten sind aus der gleichen Anwendung, die Sie wollen nicht unbedingt das gleiche Layout Skripte für jeden Teil. Ich beschloss, mit den folgenden Website-Struktur gehen:
/ Application
/ Controllers
...
/ Modelle
/ Modules
/ Default
/ Controllers
/ Layout
/ Scripts
/ Views
/ Scripts
/ AnotherModule
...
/ Scripts
Das Problem war die Einrichtung des Layouts Skripte auf einem pro Modul. Die Antwort kam durch den Einsatz einer Aktion Helper. Einrichten des Layouts auf einer pro Modul umfasst drei Schritte:
- Application.ini (oder ähnliche Konfiguration 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"
- Erstellen Sie Ihre Aktion Helper:
<? Php
/ **
* Setzt das Layout Pfad auf einem pro Modul
*
* @ Author Lloyd Watkin <lloyd@evilprofessor.co.uk>
* @ Seit 2010-01-01
* /
Klasse Pro_Controller_Action_Helper_SetLayoutPath
erstreckt Zend_Controller_Action_Helper_Abstract
{
/ **
* Setzt Layout-Pfad basierend auf Modul
* /
public function preDispatch ()
{
$ Module = $ this-> getRequest () -> getModuleName ();
if ($ bootstrap = $ this-> getActionController ()
-> GetInvokeArg ('bootstrap')) {
$ Config = $ bootstrap-> getOptions ();
if (isset ($ config [$ module] ['Ressourcen'] ['layout'] ['layoutPath'])) {
$ LayoutPath =
$ Config [$ module] ['Ressourcen'] ['layout'] ['layoutPath'];
$ This-> getActionController ()
-> GetHelper ("Layout")
-> SetLayoutPath ($ layoutPath);
}
}
}
} - Und schließlich Bootstrap der Action Helfer:
...
/ **
* Richtet Layout Skripte auf einem pro Modul
* /
protected function _initLayoutHelper ()
{
$ This-> bootstrap ('frontController');
$ Layout = Zend_Controller_Action_HelperBroker:: addHelper (
neue Pro_Controller_Action_Helper_SetLayoutPath ());
}
...