【问题标题】:Unable to get laravel/database and restler working with versioning无法让 laravel/database 和 restler 使用版本控制
【发布时间】:2014-09-13 04:38:00
【问题描述】:

我有一个现有的网站正在运行,现在我想在 api 子目录中添加一个 REST 接口。我无法让它与版本控制一起使用。我是这样安装的(没有错误):

$ php ~/bin/composer.phar create-project laravel/database --prefer-dist api
$ cd api
$ php ~/bin/composer.phar require restler/framework 3.0.0-RC6

然后我取消了 public/index.php 中与 Restler 相关的行的注释,并添加了一个新的 API 类,它只回显一个字符串。如果我通过 php artisan serve 运行它并通过 localhost URL 查看它,那么该方法有效。

现在我想启用版本控制,所以我将这些行添加到 public/index.php

use Luracast\Restler\Defaults;
Defaults::$useUrlBasedVersioning = true;

在 app/controllers 中,我创建了一个 v1 目录并将 Test.php 移到该目录中。我还在namespace A\B\v1格式的文件中添加了一个命名空间指令

当我重新启动 artisan 服务器并查询 API 时,我收到 404 错误。我试过http://localhost:8000/Testhttp://localhost:8000/v1/Test

我忘了做什么?

【问题讨论】:

    标签: laravel-4 restler


    【解决方案1】:

    这是我如何让它工作的。注意我放置 api 类文件的文件夹。

    在 index.php 中

    use Luracast\Restler\Restler;
    use Luracast\Restler\Defaults;
    Defaults::$useUrlBasedVersioning = true;
    
    $r = new Restler();
    $r->addAPIClass('A\B\Test');
    

    Test.php 保存在app/controllers/A/B/v1/Test.php

    <?php namespace A\B\v1;
    
    class Test
    {
        public function get()
        {
            return 'working';
        }
    }
    

    http://localhost:8000/v1/testhttp://localhost:8000/test 都返回 "working"

    【讨论】:

    • @Luracast:我添加了 $r->addAPIClass('Luracast\\Restler\\Resources'); index.php 中的行,以便我可以使用 explore/documentation,但它不工作并给出 500 Internal Server Error .. 我还尝试注释行 require_once '../../../vendor/restler.php' ;在实际的restler示例中,它给出了相同的500 Internal Server Error,所以我尝试将该文件(来自示例)添加到现有文件中,但它仍然对我不起作用......你能帮忙
    猜你喜欢
    • 2014-05-10
    • 2018-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-01
    • 2018-07-20
    • 2020-04-06
    • 2022-01-02
    相关资源
    最近更新 更多