2013-04-28 74 views
0

如何将我的joomla组件布局重定向到自定义布局。我一直试图通过几种方式来实现这一点,但似乎并不奏效。我有我的控制器joomla布局,如何更改主题?

class FrontpageController extends JController { 

    protected $id; 
    protected $input; 

    function __construct($config = array()) { 

     $this->input = JFactory::getApplication()->input; 
     parent::__construct($config); 
    } 

    public function display($cachable = false, $urlparams = array()) { 
     // Initialise variables. 
     $this->input = JFactory::getApplication()->input; 

     $cachable = true; 

     // Set the default view name and format from the Request. 
     $viewName = $this->input->get('view', 'frontpage'); 

     $this->input->set('view', $viewName); 

     return parent::display($cachable, $safeurlparams); 
    } 

    public function getItem() { 

     // Initialise variables. 

     $item = $this->getModel('item'); 

     $this->input->set('view','item'); 

     if (!item) { 
      JLog::add(implode('<br />', $errors), JLog::WARNING, 'jerror'); 
      return false; 


      return $item; 
     } 
    } 

} 

比以下网址index.php?option=com_mycomponent&task=getItem&layout=item&id=2571应该调用控制器的getItem方法和输出称为item

回答

1

简单的方法自定义布局的结果就是设置布局到输入之前它是由父类处理:

// Using JInput 
$this->input->set('layout', 'customLayout'); 

return parent::display($cachable, $safeurlparams); 

硬办法是自己处理整个父类的方法JControllerLegacy->display:用自己的逻辑来检索布局,并通过它来查看。