Question

How to pass parameters to the included view template ?

Controller

public function action_index3()
    {

   $view = View::factory('view1');
   $view ->set('name','Tokyo');
    $view ->set('age','1980');
    $this->response->body($view);
    }

view1.php

<?php
include 'view2.php';
?>
<?php echo $name; ?><?php echo $age; ?> 

How to pass variable to the template view2.php? Only GET include 'view2.php?name='+val?

Was it helpful?

Solution

public function action_index3()
{

    $view = View::factory('view1');
    $view ->set('name','Tokyo');
    $view ->set('age','1980');

    $subview = View::factory('view2');
    $subview->set('meow', 'woof');

    $view ->set('subview', $subview);
    $this->response->body($view);
}

Then just echo $subview in your view.

OTHER TIPS

You can also use View::set_global($key, $value)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top