繁体   English   中英

锂PHP路由不起作用

[英]Lithium PHP routes not working

我正在遵循Lithium的快速入门指南: http : //li3.me/docs/manual/quickstart

我在/var/www/my_app/app/models/Posts.php中创建了我的帖子模型

<?php

namespace app\models;

class Posts extends \lithium\data\Model {
}

?>

我在/var/www/my_app/app/controllers/PostsController.php中创建了帖子控制器

<?php

namespace app\controllers;

class PostsController extends \lithium\action\Controller {

    public function index() {
            return array('foo' => 'bar', 'title' => 'Posts');
    }
}

?>

我在/var/www/my_app/app/views/posts/index.html.php中创建了View

Lithium is less dense than <?=$foo;?>ium.

然后,快速入门指南说,我应该可以通过以下方式查看我的帖子索引页面:

http://localhost/my_app/posts

但我得到一个

Not Found

The requested URL /my_app/posts was not found on this server.

但是,如果我去只是

http://localhost/my_app 

显示Lithium随附的默认主页。

因此,我尝试通过将以下行添加到我的/var/www/my_app/config/routes.php文件中来解决此问题:

Router::connect('/posts', 'Posts::index');

但是我遇到了同样的“找不到”错误?

您需要确保在Apache中安装并启用mod_rewrite

此外,检查.htaccess文件存在,并且allow_override正确的虚拟主机集,否则.htaccess文件将被忽略。

有关更多信息,请查看文档中的“ 疑难解答”部分。

路由文档中 ,对Router::connect()方法的参数进行了更详细的说明。 ::之后的部分应该是该路由调用的操作的名称; 在您的案例index (如果没有indexAction的默认设置,则可能没有;对于Lithium不熟悉)。 您可以通过从控制器的方法名称中删除后缀Action来获得“名称”。 我建议您更全面地研究“路由”文档,以免日后头疼。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM