How to get all the variables available in a view in PHP?

折月煮酒 提交于 2019-12-28 09:15:52

问题


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.



来源:https://stackoverflow.com/questions/7218063/how-to-get-all-the-variables-available-in-a-view-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!