我正在尝试使用laravel 4。我正在使用服务提供商。在服务提供者注册中,我创建了单例实例,但我想通过接口访问它。它正在工作,我只是不知道如何访问该对象的引用接口。我的代码如下:
class AuthenticationServiceProvider extends ServiceProvider
{
public function register()
{
'App::singleton('Auth'iAuthenticate', function()
{
return new DbAuthentication();
});
}
}
然后如果我在另一个php类中写这个:
Auth'iAuthenticate::someMethod()
它返回我不能调用抽象方法,这并不让我感到惊讶。如何访问在服务提供者中创建的实例?
您可以使用$instance = App::make('Auth'iAuthenticate');
也建议使用this->app
属性。
public function register()
{
$this->app->singleton('Auth'iAuthenticate', function()
{
return new DbAuthentication();
});
}