2016-09-25 50 views
0

我想使用一些JSON API作爲遠程數據源。 我用UseMuffin找到了一個Webservice插件。Cakephp 3 - 如何註冊一個類型(控制器中的loadmodel)

我明確安裝了CakePHP(最新版)。

在我按照此插件的「用法」部分提供的所有步驟(https://github.com/UseMuffin/Webservice) 後,我被卡在Unknown repository type "Endpoint". Make sure you register a type before trying to use it.錯誤。

不知道如何註冊此類型。我試過

public function beforeFilter(Event $event) 
    { 
     $this->modelFactory(
      'Endpoint', 
      ['Endpoint', 'factory'] 
     ); 
     $this->loadModel('Articles', 'Endpoint'); 
    } 

,但得到參數2,以蛋糕\控制器\控制器:: modelFactory()必須調用,數組給定錯誤。與

+0

的'Endpoint'工廠應在調度濾波器獲得註冊附帶的插件。 ** https://github.com/UseMuffin/Webservice/blob/1.0.2/src/Routing/Filter/ControllerEndpointFilter.php#L38** – ndm

+0

可能是。但是,如果我只使用'$ this-> loadModel('Articles','Endpoint');'未知存儲庫類型「Endpoint」錯誤顯示。 – user1327

+0

我知道,這只是一個提示,所以你有一些東西可以開始調試。 – ndm

回答

0

嘗試:

use Cake\Datasource\ModelAwareTrait; 
class YourClassName 
{ 
    use ModelAwareTrait; 
    public function abc() { 
     $this->modelFactory('Endpoint', ['Muffin\Webservice\Model\EndpointRegistry', 'get']); 
     // and then 
     $this->loadModel('Articles', 'Endpoint'); 
    }  

} 
相關問題