我正在关注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中创建了我的视图
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');
但是我得到了同样的Not Found错误?
答案 0 :(得分:3)
您需要确保在Apache中安装并启用 {/ 1>。
同时检查mod_rewrite
文件是否存在,并为virtualHost正确设置.htaccess
,否则将忽略allow_override
个文件。
有关详细信息,请查看文档
中的troubleshooting部分答案 1 :(得分:0)
在Routing documentation中稍微进一步,Router::connect()
方法的参数将得到更全面的解释。 ::
之后的部分应该是路由调用的动作的名称;在你的情况下index
(或者没有,如果indexAction有一个默认设置;不熟悉Lithium)。您可以通过从Controller的方法名称中删除后缀Action
来派生“名称”。我建议更全面地探索路由文档,以避免将来遇到麻烦。