Reputation: 2653
I have seen many examples to pass data from a Joomla controller to views (e.g. here). But I need to pass a Joomla sub controller to a specific view file (view.html.php). I searched about it for a whole day and did not found a solution. Does anyone know how to do this?
Upvotes: 1
Views: 3927
Reputation: 5615
Joomla MVC is very loose and you can implement this behaviour in several ways. I think this is the most standard sequence to implement MVC in Joomla:
But you could handle the params in 3. and pass them on to the model; this really is a matter of style/taste. Since Joomla allows you to invoke your model from the view with $this->get('Data') for example, there is no room for passing params; you can however choose to invoke $model->getData2($param1,$param2).
The basic calls are:
JApplication::getUserStateFromRequest()
which in a single call reads the input and falls back on the previously saved session data;
setUserState to persist this info in the session and getUserState to be used in the model to retrieve the data.
You can however simply redirect passing the params in the url; then use the view.html.php to parse the input and set the internal state of the model before calling methods ($model->setState), or avoid redirect entirely and load the models and view from the controller (which seems a more standard and easy approach to MVC, but is seldom seen in Joomla).
Directly invoking the view from the controller
$vName = 'yourview';
$vFormat = 'html'; // raw
if ($view = $this->getView($vName, $vFormat)) {
$model = $this->getModel($vName);
$model->setState('filter.type', $type);
$view->setModel($model, true);
// Push document object into the view.
$view->assignRef('document', $document);
$view->display();
}
Upvotes: 4