Search code examples
phparraysmodel-view-controllerjoomlajoomla3.3

Pass an array variable from controller to view in Joomla


I am redirecting to view from a controller and I want to send an array from controller to view. I am using :

$data = JRequest::getVar('jform', array(), 'post', 'array');

I want to pass this array to view named confirmation.

$this->setRedirect(JRout::-('index.php?option=com_contact&view=confirmation');

This redirects to view but how can I access the $data array in the view file ?


Solution

  • You shouldn't be sending data from the controller to the view. Joomla is a MVC (model view controller) design, as such your business logic for getting, setting, and modifying data should be in your model.

    Modify your code to follow MVC design and you should have access to your data object in your view through the model.

    • The controller's job is to get the view for the user
    • The view's job is to display stuff for the the user and calls on the model
    • The model's job is to know about the data the view needs.