簡體   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