Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to pass data from controller to view in joomla ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.39k
    Comment on it

    Hello Readers,

    The below blog display the data from joomla component controller (C1) to joomla view (V1).

    Suppose, we have a data in joomla controller.php and we want to rendered the data in joomla view (for example in component com_mycomponent).

    Below, Example code show how to render the data in joomla view.

    Step 1 : In Controller use the below code : (com_mycomponent->controller.php)

    $view = $this->getView('viewname','format'); //get the view
    $view->myVariable = 'Hello'; //set the data to the view
    $view->display(); //show the view

    Step 2 : In View : (com_mycomponent->views->viewname->view.html.php)

    class MycomponentViewItem extends JViewLegacy
    {
      /** @var  string   my variable */
      public $myVariable;
    
      public function display($tpl = null)
      {
        $myVariable = $this->myVariable; // use the $view->myVariable variable inside view.html.php.
        //...
        $this->assignRef( 'myVariable', $myVariable );
      }
    }  

    Step 3 : In View : (com_mycomponent->views->viewname->tmpl->default.php)

    display the data here :

    print_r($this->myVariable); die;

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: