I'm new in Laravel, I'm trying to understand how it works. I have setup this library as defined.
https://github.com/thujohn/twitter-l4
Examples works perfect when I define use with only Twitter; Shown below
use Stream;
use Twitter;
class GoController extends \BaseController{
function go($id){
return Twitter::getUserTimeline(array('screen_name' => 'thujohn', 'count' => 20, 'format' => 'json'));
}
}
but it throws this error when I use Thujohn\Twitter\Twitter;
use Stream;
use Thujohn\Twitter\Twitter;
class GoController extends \BaseController{
function go($id){
return Twitter::getUserTimeline(array('screen_name' => 'thujohn', 'count' => 20, 'format' => 'json'));
}
}
Non-static method Thujohn\Twitter\Twitter::getUserTimeline() should not be called statically, assuming $this from incompatible context
So, I'm unable to understand why I can't use the second form?
Beacuse in the second example you're using the class directly, which happens to have the same name as the alias accessor.
What you see called statically is a Façade, which actually instantiates the class by using a static method (I'm not really good at explaining things...)
If you followed the instructions you should have created an Alias in the config/app.php
file.
'Twitter' => 'Thujohn\Twitter\TwitterFacade',
And this alias is the very Twitter
class (i.e., the façade) you need to call, and that you see called in the documentation.
So, remove the use
statement use Thujohn\Twitter\Twitter;
and your code will be using the "Twitter" alias (like it did in the first example), i.e. will call the Facade accessor.
use Stream;
class GoController extends \BaseController
{
public function go($id)
{
return \Twitter::getUserTimeline(array('screen_name' => 'thujohn', 'count' => 20, 'format' => 'json'));
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句