douzouchang7448
2013-04-28 12:48 阅读 24
已采纳

joomla布局,如何改变主题?

How can I redirect my joomla components layout to a custom layout. I have been trying to achieve this in couple of ways but doesn't seems to work. I have my controller

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;
        }
    }

}

than the following url index.php?option=com_mycomponent&task=getItem&layout=item&id=2571 should call the controllers getItem method and output the results in a custom layout called item

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dqzow3859 dqzow3859 2013-04-29 10:14

    Easy way is to set layout into input before it's processed by parent class:

    // Using JInput
    $this->input->set('layout', 'customLayout');
    
    return parent::display($cachable, $safeurlparams);
    

    Hard way is to handle whole parent class JControllerLegacy->display method by yourself: use own logic to retrieve layout and pass it to view.

    点赞 评论 复制链接分享

相关推荐