根據CI的文檔,CodeIgniter使用一個基於段的方法,例如:如何讓CodeIgniter接受「查詢字符串」網址?
example.com/my/group
如果我想找到一個特定的組(ID = 5),我可以訪問
example.com/my/group/5
和Controller,定義
function group($id='') {
...
}
現在我想用傳統的方法,其中CI來電「查詢字符串」 URL。例如:
example.com/my/group?id=5
如果我直接去這個網址,我得到一個404頁找不到。那我該如何啓用它?
我仍然得到一個404錯誤CodeIgniter位於'我的。 server.com/project/ci',有'my.server.com/project/ci/index.php','my.server.com/project/ci/.htaccess'和'my.server.com/project/ci/system/application'。 – zihaoyu 2010-05-24 17:33:47
我的不好,我有剛剛意識到你問了什麼。 你不能混合和匹配查詢字符串/段的方法。如果你想使用段來訪問控制器/方法,你需要通過該方法以及example.com/my/group/5 /'來傳遞id。或者你需要在方法的頂部包含'$ id = $ this-> input-> get('id)';',如果你真的想把它從查詢字符串中取出。 或者您可以啓用查詢字符串並使用它來選擇控制器和方法以及'my.server.com/project/ci/index.php?c = my&m = group&id = 5'。 – WeeJames 2010-05-25 07:14:11
謝謝,我把'$ id = $ this-> input-> get('id')'放在我的控制器的開頭,並設置了'$ config ['uri_protocol'] =「QUERY_STRING」;'在config.php中。但是'example.com/my/group?id = 5'仍然不起作用。我得到了404錯誤。還有什麼應該做的? – zihaoyu 2010-05-27 16:56:51