facade的问题
1.在app/下创建
Ftest/Tester/Facade/TesterFacade .php
2.app/Ftest/Tester/tester.php
3.app/Ftest/Tester/TesterServiceProvider.php
4.在app.php中添加了
autoload;
5.在controller中测试
echo Tester::test();
出错!!!
如果 写上
正确!
怎么破!!!
Ftest/Tester/Facade/TesterFacade .php
<?php namespace Ftest\Tester\Facade;
class TesterFacade extends \Illuminate\Support\Facades\Facade
{
protected static function getFacadeAccessor() { return 'tester'; }
}
2.app/Ftest/Tester/tester.php
<?php namespace Ftest\Tester;
class Tester{
public function test(){
return 'facade test';
}
}
3.app/Ftest/Tester/TesterServiceProvider.php
<?php namespace Ftest\Tester;
class TesterServiceProvider extends \Illuminate\Support\ServiceProvider{
protected $defer = false;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->bind('tester', function()
{
return new Tester;
});
}
}
4.在app.php中添加了
providers
'Ftest\Tester\TesterServiceProvider'
aliases
'Tester' => 'Ftest\Tester\Facade\TesterFacade'
autoload;
5.在controller中测试
echo Tester::test();
出错!!!
Symfony \ Component \ Debug \ Exception \ FatalErrorException
Call to undefined method Ftest\Tester\Facade\TesterFacade::test()
如果 写上
App::bind('tester',function(){
return \Ftest\Tester\Tester;
});
Tester::test();
正确!
怎么破!!!
3 个回复
mvc999
赞同来自: kkkdd 、FiveSay
还有你给的例子:
1.在app/下创建
Ftest/Tester/Facade/testFacade.php
<?php
namespace Ftest\Tester\Facade;
class TesterFacade extends \Illuminate\Support\Facades\Facade
{
protected static function getFacadeAccessor() { return 'tester'; }
}
名字都写错了
kkkdd - phper
赞同来自: 安正超
仔细看了一下php.net手册上的介绍。非常感谢! :smile:
kkkdd - phper
赞同来自:
话说我写的这个为什么没有起作用?
“”Ftest/Tester/TesterServiceProvider“”
求教...