9

in my controller i have an public variable i want to use in my view.

public $header = array("show_menu"=>true);

Traditional i would pass variables as an array to the load->view("incl_header",$header) function, however i have noticed that in my view i can retrieve variables of my controller like so:

echo  $this->header['show_menu'];

Are there any problems retrieving variables like this in my view file?

I am using codeigniter 2.1.3

3
  • 1
    In your view do var_dump($this); and you will see why you can. Commented Apr 15, 2013 at 20:40
  • oke so no problem if i use this method? Commented Apr 15, 2013 at 20:41
  • 4
    Yes, it is fine, it's just not consistent with what CI users will do. Try to stick with the normal way of accessing the variable using CI just in case such a use will not be possible in future versions. Commented Apr 15, 2013 at 20:43

1 Answer 1

3

It's possible to do it like that.

If you use var_dump($this) you can see all the variables that are availible in your view.

It's not the normal codeigniter way of retrieving variables in your view.

How ever this might change in futeure releases of codeigniter so you must keep that in mind when using this method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.