正如我在标题中所说,我想使用带有laravel 5.1的Blade获取模板中的所有已分配变量
示例:
控制器:
class Ctrl extends Controller
{
public function index() {
$title = "i'm a title";
$name = "i'm a name";
return view('myview', compact('title', 'name'));
}
}
模板:myview.blade.php
@getVars()
服务提供商:
class getVarsServiceProvider extends ServiceProvider {
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
Blade::directive('getVars', function() {
// MUST return array('title' => "i'm a title", "name" => "i'm a name");
return "all vars"; // <----
});
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
答案 0 :(得分:0)
调用get_defined_vars()会为你工作吗?