2014-09-05 20 views
-1

嗨我在尝试在的laravel-4中显示数据时出现此错误。我现在用的是Facebook SDK dev-master发布将facebook数据传递给routes.php查看

这是我error:

Trying to get property of non-object (View: C:\wamp\www\irishrail.tld\app\views\user\authed.blade.php) 

这是我view:

<div class="cover authed"> 
     <div class="profile"> 
      <div class="avatar"> 
       <img height="100%" width="100%" src="{{$cred->profile_image_url}}" alt=""> 
      </div> 
     </div> 
    </div> 
    <div class="title-bar"> 
     Congrats {{$cred->name}} 
    </div> 
    <div class="content"> 
     <form action="/" method="post"> 
      <input type="text" name="code" class="field" placeholder="Redemption Code"> 
      <button class="btn btn-green">Claim your ticket</button> 
     </form> 
    </div> 

这是我route:

Route::get('login/facebook/callback', function(){ 
    $code = Input::get('code');//error 

    $facebook = new Facebook(Config::get('facebook')); 
    $uid = $facebook->getUser();//Gets the user id 

    //Get User Details from FB 
    $credentials = $facebook->api('/me'); 
    $photo = 'http://graph.facebook.com/'.$uid.'/picture'; 

    $credentials['name'] = $credentials['first_name']." ".$credentials['last_name']; 
    $credentials['profile_image_url'] = $photo;//Add photo to the credentials 

    return View::make('user.authed')->with('cred', $credentials); 
}); 
+0

看起来像'$ cred'是一个数组。试试'$ cred ['profile_image_url']' – user3158900 2014-09-05 17:05:54

回答

0

在你的路线定义$credentials为数组,在你的vi如果您正在通过对象运算符访问它。

{{ $cred['name'] }} 

应该在您的视图中为您工作。

另一种选择是将您的数组强制转换为对象。在您的路线中,在返回视图之前,请执行以下操作:

$credentials = (object) $credentials; 

然后,您可以像访问上面的示例一样访问视图中的数据。

顺便说一句,这与facebook sdk或laravel无关,这是一个普通的php错误。