Restler PHP API 框架 URL 路由

发布于 2024-12-17 14:29:07 字数 1259 浏览 0 评论 0原文

我有一个关于框架的问题。我的 CRUD 基于您的实例。我有这个 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] => [电子邮件受保护] [3] => )

我想在这里实现的是获取query1query2的值?我该怎么做?

谢谢。

I have a question regarding the framework. I based my CRUD on your live example. I have this URL:

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

In my api.php file, I used GET method on this request:

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

Then on my control.php,

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

The response body of this is

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

What I want to achieve in here is get the values of query1 and query2? How can I do this?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乞讨 2024-12-24 14:29:08

我创建了以下概念验证并对其进行了测试并确保其有效!

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

为了托管上面的API,我使用以下index.php(网关)

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

所以我应该能够轻松地将它传递给另一个类另一个方法

I have created the following proof of concept and tested it and made sure it works!

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

For hosting the API above I use the following index.php (gateway)

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

When I call

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

or

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

or

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

I get

"mama papa"

So I should be able to pass it to another class another method easily

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文