2011-11-24 65 views
0

我有一個關於框架的問題。我基於您的現場示例中的我的CRUD。我有這個網址:Restler PHP API框架URL路由

http://mydomain.com/test/index.php/api/t1/module1/[email protected]?query1=mama&query2=papa 

在我api.php文件,我對這個請求中使用GET方法:

public function __construct(){ 
    $this->dp = new Control(); 
} 

public function get($id=NULL, $id2=NULL, $id3=NULL, $id4=NULL) 
{ 
    switch($id) 
    { 
     case "t1": 
      return $this->dp->t1(func_get_args()); 
     break; 
     case "t2": 
      return $this->dp->t2(func_get_args()); 
     break; 
     default: 
      throw new RestException(400); 
     break; 
    } 
} 

然後在我的control.php

public function t1($numbers) { 
print_r($numbers); 
} 

這是的響應正文是

陣列 ( [0] => T1 [1] =>模塊1 [2] => [email protected] [3] => )

我要實現在什麼這裏得到的值爲查詢1查詢2?我怎樣才能做到這一點?

謝謝。

回答

0

我已經創建了以下概念驗證並對其進行了測試,並確保其可行!

<?php 
class Api { 
    public function get($id = NULL, $id2 = NULL, $id3 = NULL, $id4 = NULL, $query1 = NULL, $query2 = NULL) { 
     return "$query1 $query2"; 
    } 
} 

主辦上述我使用下面的index.php(網關)的API

<?php 
require_once '../../restler/restler.php'; 
require_once 'api.php'; 
$r = new Restler(); 
$r->addAPIClass('Api'); 
$r->handle(); 

當我打電話

http://restler2.dev/test/url_routing/index.php/api/t1/module1/[email protected]?query1=mama&query2=papa 

http://restler2.dev/test/url_routing/index.php/api/t1/module1?query1=mama&query2=papa 

http://restler2.dev/test/url_routing/index.php/api/t1?query1=mama&query2=papa 

我得到

"mama papa" 

所以我應該能夠很容易傳遞到另一個類的另一種方法

+0

感謝您的答覆。它不起作用阿魯爾。我現在所做的是從** $ _ SERVER ['QUERY_STRING'] **獲取值,但對我來說不是最好的方法。 –

+0

它工作正常!我已經用概念驗證測試並更新了我的示例。如果這不是你想要的,請告訴我 – Arul