English 中文(简体)
URL 路线
原标题:Restler PHP API framework URL routing
  • 时间:2011-11-24 11:42:55
  •  标签:
  • php
  • api
  • rest

我对框架有一个问题。 我以你的活榜样为本。 我有:

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;
    }
}

然后在我的<>控制.php上,

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

答复机构

Array ( [0] => t1 [1] => module1 [2] => [email protected] [3] => )

在这里,我想实现的是query1query2? 我如何能够这样做?

感谢。

最佳回答

我提出了以下概念证据,并对这一概念进行了测试,并确保它发挥作用!

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

在主办上述年度审评时,采用以下索引:

<?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"

因此,我应该能够把另一种方法很容易地转往另一类。

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签