Welcome Guest, Not a member yet? Register   Sign In
Accessing controller variables in the viewer
#1

[eluser]dedavai[/eluser]
I'm having trouble accessing variables created inside the controller from within the viewer. For example, inside the controller (home.php) I have the following:
Code:
function view() {
...
$sub = false;
$this->load->view('home_view');
}
and inside the view file (home_view.php) I have
Code:
<input type="text" name="cp" value="<?=($sub ? "CP value" : "");?>">
However, the $sub never makes it from the controller to the viewer. Is there a special way to reference the variables ?
#2

[eluser]Michael Wales[/eluser]
Variables must be passed within an array to the view from the controller.

Controller:
Code:
function view() {
  $data['sub'] = FALSE;
  $this->load->view('home_view', $data);
}

View:
Code:
<input type="text" name="cp" value="<?= $sub ? "CP Value" : ""); ?>">

Please read the View documentation and the Loader documentation.




Theme © iAndrew 2016 - Forum software by © MyBB