Zend Framework Per-Modul berbasis pengaturan
Saya telah membuat tindak lanjut untuk posting ini yang memerlukan konfigurasi kurang, silakan lihat Tata Letak Modul Berbasis - Zend Framework .
Bila menggunakan kerangka Zend dengan modul, yang nyata bahwa jika Anda menjalankan berbagai (sub-) situs dari aplikasi yang sama Anda tidak selalu menginginkan hal yang sama script tata letak untuk setiap bagian. Saya memutuskan untuk pergi dengan struktur situs berikut:
/ Aplikasi / Controllers ... / Model / Modules / Default / Controllers / Layout / Scripts / Views / Scripts / AnotherModule ... / Scripts
Masalahnya adalah menyiapkan script tata letak pada basis per-modul. Jawabannya datang melalui menggunakan Pembantu Aksi. Menyiapkan layout pada basis per-modul melibatkan tiga langkah:
- Application.ini (atau setup konfigurasi serupa):
admin.resources.layout.layoutPath = APPLICATION_PATH "/ modules / admin / layouts / script" default.resources.layout.layoutPath = APPLICATION_PATH "/ modules / default / layouts / script" member.resources.layout.layoutPath = APPLICATION_PATH "/ modules / anggota / layouts / script" affiliate.resources.layout.layoutPath = APPLICATION_PATH "/ modules / afiliasi / layouts / script"
- Buat Helper Aksi Anda:
<? Php / ** * Mengatur jalur tata letak pada basis per-modul * * @ Author Lloyd Watkin <lloyd@evilprofessor.co.uk> * @ Sejak 2010-01-01 * / kelas Pro_Controller_Action_Helper_SetLayoutPath meluas Zend_Controller_Action_Helper_Abstract { / ** * Set tata letak jalan berdasarkan modul * / fungsi publik preDispatch () { $ Modul = $ this-> getRequest () -> getModuleName (); if ($ bootstrap = $ this-> getActionController () -> GetInvokeArg ('bootstrap')) { $ Config = $ bootstrap-> getOptions (); if (isset ($ config [$ modul] ['sumber'] ['tata letak'] ['layoutPath'])) { $ LayoutPath = [Modul $] $ config ['sumber'] ['tata letak'] ['layoutPath']; $ This-> getActionController () -> GetHelper ('tata letak') -> SetLayoutPath ($ layoutPath); } } } }
- Dan terakhir metode bootrap ini pembantu tindakan:
... / ** * Mengatur tata letak script pada basis per-modul * / fungsi lindung _initLayoutHelper () { $ This-> bootstrap ('frontController'); $ Layout = Zend_Controller_Action_HelperBroker :: addHelper ( baru Pro_Controller_Action_Helper_SetLayoutPath ()); } ...

















































