zf動態Layout

bootstrap.php 新增pluginClass處理動態Layout

<?php
    Zend_Layout::startMvc(
    array(
        'layoutPath' => '/application/views/layouts/scripts',
        'layout' => 'layout',
        'pluginClass' => 'GPMS_Util_Layout'
    )
);

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
}

自訂動態Layout Class,預設導到portal.phtml,其他by module切割

<?php
class GPMS_Util_Layout extends Zend_Layout_Controller_Plugin_Layout
{
  public function preDispatch(Zend_Controller_Request_Abstract $request)
  {
    switch ($request->getModuleName()) {
        case 'default':
            $this->_moduleChange('portal');
        break;
        default:
        break;
    }
  }
  protected function _moduleChange($moduleName) {
    $this->getLayout()->setLayout($moduleName);
  }
}

沒有留言:

橫式廣告