2010-11-28 13 views

Antwort

6

ich eine Layout-Plugin, Layouts zu wechseln, wenn ein Nicht-Standard-Modul aufgerufen wird:

class MyApplication_Layout_Controller_Plugin_Layout extends Zend_Layout_Controller_Plugin_Layout 
{ 

    public function preDispatch(Zend_Controller_Request_Abstract $request) 
    { 
     switch ($request->getModuleName()) { 
      case 'admin': $this->_moduleChange('admin'); 
     } 
    } 

    protected function _moduleChange($moduleName) { 
     $this->getLayout()->setLayoutPath(
      dirname(dirname(
       $this->getLayout()->getLayoutPath() 
      )) 
      . DIRECTORY_SEPARATOR . 'layouts/scripts/' . $moduleName 
     ); 
     $this->getLayout()->setLayout($moduleName); 
    } 

} 

Da ist in meinem Bootstrap, ich dies tun:

Zend_Layout::startMvc(
      array(
       'layoutPath' => self::$root . '/application/views/layouts/scripts', 
       'layout' => 'layout', 
       'pluginClass' => 'MyApplication_Layout_Controller_Plugin_Layout' 
      ) 
     ); 

Die nicht standardmäßigen Layouts werden in einen Ordner mit dem Namen " nach dem Modul, sieht so meine Verzeichnisstruktur wie folgt aus:

/path/to/application/views/layouts/scripts/layout.phtml --> default layout 

/path/to/application/views/layouts/scripts/admin/admin.phtml --> admin layout 
+0

danke ... sorry für die Antwort spät –

1

//in controller 
$this->_helper->layout->setLayout('layoutName'); 

versuchen Sie Ihr Modul Layout zu layoutName.phtml in Sicht/scripts Ordner wechseln wird;)

+0

Dies funktioniert überhaupt nicht. Sollte sein $ this -> _ helper-> layout-> setLayout ('layoutname') – Andy

+0

Ja, du hast offensichtlich Recht. Ich habe es repariert. –

+0

Schnell und effektiv, danke für den Tipp @ TomášFejfar! –

1

Dies ist falsch. Die Linie:

class MyApplication_Layout_Controller_Plugin_Layout extends end_Layout_Controller_Plugin_Layout 

sollte extends Zend_Controller_Plugin_Abstract sein. Andernfalls erhalten Sie einen Fehler bezüglich mvcSuccessfulActionOnly.