【发布时间】:2014-12-25 07:19:54
【问题描述】:
在我的App\Providers\RouteServiceProvider 中,我确实创建了方法register:
public function register()
{
$this->app->bindShared('JustTesting', function($app)
{
die('got here!');
// return new MyClass;
});
}
我应该在哪里使用它?我确实在App\Http\Controllers\HomeController 中创建了一个方法:
/**
* ReflectionException in RouteDependencyResolverTrait.php line 53:
* Class JustTesting does not exist
*
* @Get("/test")
*/
public function test(\JustTesting $test) {
echo 'Hello';
}
但是没用,我也不能用 $this->app->make('JustTesting');
如果我按照下面的代码进行操作,它可以工作,但我想注入控制器。
/**
* "got here!"
*
* @Get("/test")
*/
public function test() {
\App::make('JustTesting');
}
我应该如何像我想要的那样绑定?如果不允许,我为什么要使用bindShared 方法?
【问题讨论】:
标签: php laravel laravel-routing laravel-5