【问题标题】:CRUD with AngularJS and Slim PHP 404 not found未找到带有 AngularJS 和 Slim PHP 404 的 CRUD
【发布时间】:2014-09-05 06:37:24
【问题描述】:

我熟悉RESTful api (CRUD) 和AngularJSSlim PHP 框架。我正在关注本教程:http://www.blog.iamaronbarbosa.com/building-a-basic-crud-application-using-angularjs-and-slim-php-framework-part-1/。而当应用程序试图GET数据(文件:angular-crud/slim/index.php),

function ListCtrl($scope, $http) {
    $http.get('api/users').success(function(data) {
        $scope.users = data;
    });
}

我收到错误代码说明, Status Code: HTTP/1.1 404 Not Found

获取数据的网址是:http://localhost/angular-crud/slim/api/users

编辑

但是,如果我将 url 应用为 http://localhost/angular-crud/slim/api/index.php/users 它会很好地返回数据。必须包含index.php 吗?如果没有,是否有使用 url http://localhost/angular-crud/slim/api/users 检索数据的解决方法?

我对这个领域很陌生,如果问题含糊不清,我深表歉意。我尝试检查端口并使用RESTClient 运行测试,但最终空手而归。非常感谢您对此事的专家建议:)

【问题讨论】:

    标签: angularjs rest get http-status-code-404 slim


    【解决方案1】:

    需要通过 index.php 进行路由表明 URL 重写存在问题。来自文档:

    Slim 无需 URL 重写即可工作。在这种情况下,您必须 包括您在其中实例化和运行的 PHP 文件的名称 资源 URI 中的 Slim 应用程序。

    有关如何在 Apache 和 nginx 中正确路由 URL 的详细信息,请参阅 Slim 文档的“Route URL Rewriting”部分。

    【讨论】:

    • 谢谢先生的回答。这是一个重写问题:)
    【解决方案2】:

    我认为您的项目中必须有一个 .htaccess 文件,该文件将 URL 从 http://localhost/angular-crud/slim/api/users 重写为 http://localhost/angular-crud/slim/ api/index.php/用户。检查您的本地主机是否允许 .htaccess 覆盖

    【讨论】:

    • 非常感谢先生,我会检查一下
    猜你喜欢
    • 2015-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-21
    • 1970-01-01
    相关资源
    最近更新 更多