I am using Laravel 5. I would like to know which are all variables passed to a view inside the view itself.
由于所有变量都在视图范围内,我想我可以使用通用PHP函数:get_defined_vars();
http://php.net/manual/en/function.get-defined-vars.php
Something like this:
// resources/view/home.blade.php
<html>
<body>
<?php print_r(get_defined_vars()); ?>
</body>
</html>
但我想知道是否有更好的方法(大约View::getData()
个)
Note: get_defined_vars() deosn't work becausee it returns hundreds of useless variables (Laravel components)
这是一个使用print_r(get_defined_vars())
的代码片段(部分)(我认为它在无限递归循环中):
Array
(
[__path] => C:\net\laravel\storage\framework\views/8e030a77b0bdbacc2c4182fc04420d1d
[__data] => Array
(
[__env] => Illuminate\View\Factory Object
(
[engines:protected] => Illuminate\View\Engines\EngineResolver Object
(
[resolvers:protected] => Array
(
[php] => Closure Object
(
[this] => Illuminate\View\ViewServiceProvider Object
(
[app:protected] => Illuminate\Foundation\Application Object
(
[basePath:protected] => C:\net\laravel
[hasBeenBootstrapped:protected] => 1
[booted:protected] => 1
[bootingCallbacks:protected] => Array
(
[0] => Closure Object
(
[static] => Array
(
[instance] => Illuminate\Bus\BusServiceProvider Object
(
[defer:protected] => 1
[app:protected] => Illuminate\Foundation\Application Object
*RECURSION*
)
)
[this] => Illuminate\Foundation\Application Object
*RECURSION*
)
[1] => Closure Object
(
[static] => Array
(
[instance] => Illuminate\Translation\TranslationServiceProvider Object
(
[defer:protected] => 1
[app:protected] => Illuminate\Foundation\Application Object
*RECURSION*
)
)
[this] => Illuminate\Foundation\Application Object
*RECURSION*
)
)
[bootedCallbacks:protected] => Array
(
)
[terminatingCallbacks:protected] => Array
(
)
[serviceProviders:protected] => Array
(
[0] => Illuminate\Events\EventServiceProvider Object
(
[app:protected] => Illuminate\Foundation\Application Object
*RECURSION*
[defer:protected] =>
)