tags:

views:

35

answers:

1

Here are some sample methods from my Controller class. Now when the user clicks the New button $task=add is sent to the Controller and the add() method is called. As you can see it does not really do anything, it just creates a url and forwards it off to the correct view. Is this the correct way of doing things in the MVC pattern?

    /**
 * 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);
}
A: 

I don't believe this is the correct way. I would suggest looking at some of the core Joomla! code to see how it's done. A great, easy example that I always look at is Weblinks. Take a look at what they do in the edit function of their controller:

.../components/com_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();
    }

They set the view and layout variables and then call parent::display to let Joomla! go out and display that view/layout.

Will Mavis
Do you know what the weblinks edit() method gives me that mine does not?
jax