2012-05-30 67 views
0

我正在使用Restler 2.1.5,並且我有一個保護索引方法的類。Restler映射保護方法

protected function index($id){ 
//do something 
} 

我添加了新的受保護的方法,但無法調用該方法。

protected function method(){ 
//do stuff 
} 

當我打電話http://localhost/api/index.php/class?key=foo 它運行一切OK

但是,當我打電話 http://localhost/api/index.php/method?key=foo 它給了我沒有找到

什麼可導致此?

回答

1

這是因爲你看錯了地方!

試試下面的網址,而不是

http://localhost/api/index.php/class/method?key=foo

如果不通過''(空字符串)作爲第二個參數類$r->addAPIClass()名字將被包括在路由,因此你需要包括它在你的URL過於

你也應該明白優先的模糊性和秩序,閱讀this thread會幫你

+0

仍然沒有工作。在示例中,如果添加以下內容,則在類Simple中的_005_protected_api: 'protected function index($ a){ \t \t return「hello」。$ a; }' ,然後如果你打電話 HTTP://localhost/examples/_005_protected_api/index.php/simple/restricted鍵= rEsTlEr2 它將返回'hellorestricted',換句話說,它調用索引方法 由於'index'作爲參數,它將始終調用索引方法,即使我指出方法名稱。我對嗎? –

+0

這是優先級問題的順序。我已經通過鏈接到解決方案更新了我的答案 – Luracast