2013-04-06 48 views
0

我下面的快速入門指南,鋰:http://li3.me/docs/manual/quickstart鋰PHP的路線不工作

我創造了我的帖子模型/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 

Lith自帶的默認主頁顯示ium。

所以,我想通過加入這一行我/var/www/my_app/config/routes.php文件解決了這個問題:

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

但我得到同樣未找到錯誤?

回答

3

您需要確保mod_rewrite已安裝並在您的Apache中啓用了

還要檢查.htaccess文件是否存在,並且allow_override已正確設置爲虛擬主機,否則.htaccess文件將被忽略。

有關更多信息,請參閱文檔中的troubleshooting部分

+0

我運行這個命令啓用mod_rewrite:「sudo a2enmod rewrite」,並修改了「/ etc/apache2/sites-available/default」,並將AllowOverride設置爲「All」。 – 2013-04-07 16:39:47

+0

唉!不能相信我忘了檢查我的虛擬主機指令。感謝提醒,它做到了! :) – 2013-09-07 21:20:13

0

Routing documentation的稍微更進一步,Router::connect()方法的參數更詳細地解釋。 ::之後的部分應該是路由所調用的動作的名稱;在你的情況index(或者什麼也沒有,如果有一個indexAction的默認設置;不熟悉Lithium)。您通過從您的Controller的方法名稱中刪除後綴Action來派生出「名稱」。我建議您更全面地瀏覽路由文檔,以免將來讓您頭疼。

+0

好吧,現在更有意義。 我將路線改爲 Router :: connect('/ posts','Posts :: index'); 但我仍然得到相同的未找到錯誤。 – 2013-04-06 18:15:25

+0

你確定已經安裝並啓用了'mod_rewrite'嗎?您的'.htaccess'文件是否存在並且是否正確設置了'allow_override'?查看[疑難解答]部分(http://lithify.me/docs/manual/getting-started/troubleshooting.wiki) – thaJeztah 2013-04-06 18:41:39

+0

@thaJeztah yes mod_rewrite是你想寫的問題作爲答案,所以我可以選擇它。 – 2013-04-07 14:58:00