How to get all the variables available in a view i

2019-01-16 16:42发布

问题:

I need to see all the variables that are available in a view. I am a front end developer so I mostly work in the views directory. I don't always know which variables are being passed to the templates by the back end dev. Instead of asking him every time an easy solution would be some type of snippet that I can temporarily paste into the view that I'm working on so I can see all the available variables and even better if I can also see their types and values.

I tried this:

<pre><?php var_dump(get_defined_vars()); ?></pre>

But since I am using Codeigniter it also shows all the other tons and tons of variables that are passed in by the framework.

I only want to display the variables that were passed specifically from the controller that loaded the view. Is there any way to do this?

回答1:

var_dump($this->_ci_cached_vars);


回答2:

One possibility could be to do something like this:

$data['user'] = $user;
$data['cart'] = $cart;
$data['data'] = $data;

$this->load->view('view', $data);

If you did something like this, then you could always access a data array that looked the same as before it was parsed for the view.

Then you could use something like print_r or whatever you wanted to take a look at the array.