1
我是新手與類(更糟糕的命名空間等),所以我知道必須創建FacebookMyClass.php類主要類是(autoload.php
,Facebook.php
,FacebookApp.php
等),那麼我的原型:Facebook的PHP SDK 5:擴展類
<?php
// I guess
namespace Facebook;
// Do I must 'use' or extending other class(es)?
// use ;
class FacebookMyClass extends Facebook {
// Do I have to "re-declare" parent's vars?
private $my_private_var;
public $my_public_var;
private $access_token;
// The main thing, I think, is how class is constructed
// public function __construct(array $config = []) {
public function __construct($id, $secret) {
// This will work? Need parameters?
parent::__construct();
}
public function accessParentProtectedVars($idfanpage) {
// How can I call/link to Facebook object/request/response?
$object = $this->get('/' . $idfanpage . '/albums?fields=name,id', $this->access_token);
}
private function getTokens($params = []) {
// code...
$this->access_token = '...';
}
}
?>
問題是:我該如何擴展Facebook \ Facebook類(es)?
你爲什麼不使用FacebookResponses getBody()方法?它返回body屬性。 '$ body = $ datos-> getBody();' – lordthorzonus
@lordthorzonus你讓我的一週!儘管它沒有回答我關於擴展類的問題,但它爲我解決了一個大問題,Facebook文檔沒有(我希望可以像CodeIgniter用戶指南)。 – quantme
希望下面的答案給你你正在尋找的解釋。 lordthorzonus是正確的,但如果可能的話,總是更好地使用類的現有方法,只有在定製超出可用範圍時才需要擴展或實現。 – Sean