Joomla将代码转发到视图…这是正确的方法吗?

Joomla将代码转发到视图…这是正确的方法吗?,joomla,Joomla,下面是我的Controller类中的一些示例方法。现在,当用户单击新按钮时,$task=add被发送到控制器并调用add()方法。正如您所看到的,它实际上并没有做任何事情,它只是创建一个url并将其转发到正确的视图。这是MVC模式中正确的做事方式吗 /** * New button was pressed */ function add() { $link = JRoute::_('index.php?option=com_myapp&c=apps&view=

下面是我的
Controller
类中的一些示例方法。现在,当用户单击新按钮时,$task=add被发送到控制器并调用add()方法。正如您所看到的,它实际上并没有做任何事情,它只是创建一个url并将其转发到正确的视图。这是MVC模式中正确的做事方式吗

    /**
 * New button was pressed
 */
function add() {
    $link = JRoute::_('index.php?option=com_myapp&c=apps&view=editapp&cid[]=', false);
    $this->setRedirect($link);
}


/**
 * Edit button was pressed - just use the first selection for editing
 */
function edit() {
    $cid = JRequest::getVar( 'cid', array(0), '', 'array' );
    $id = $cid[0];
    $link = JRoute::_("index.php?option=com_myapp&c=apps&view=editapp&cid[]=$id", false);
    $this->setRedirect($link);
}

我认为这不是正确的方法。我建议你看看核心的Joomla!代码来查看它是如何完成的。我经常看到的一个好的、简单的例子是Weblinks。看看他们在控制器的编辑功能中做了什么:

../components/com\u weblinks/controllers/weblink.php

    function edit()
    {
            $user = & JFactory::getUser();

            // Make sure you are logged in
            if ($user->get('aid', 0) < 1) {
                    JError::raiseError( 403, JText::_('ALERTNOTAUTH') );
                    return;
            }

            JRequest::setVar('view', 'weblink');
            JRequest::setVar('layout', 'form');

            $model =& $this->getModel('weblink');
            $model->checkout();

            parent::display();
    }
函数编辑()
{
$user=&JFactory::getUser();
//确保您已登录
如果($user->get('aid',0)<1){
JError::raiseError(403,JText::u('ALERTNOTAUTH');
返回;
}
JRequest::setVar('view','weblink');
JRequest::setVar('layout','form');
$model=&$this->getModel('weblink');
$model->checkout();
父::显示();
}

他们设置视图和布局变量,然后调用parent::display让Joomla!走出去显示那个视图/布局。

你知道weblinks edit()方法给了我什么,而我的方法没有吗?