【发布时间】:2012-03-18 22:05:55
【问题描述】:
编辑:
已解决 - mod_rewrite 是问题
我无法按照教程中的说明让 CI 工作。 无论我如何摆弄路径或设置 - 它都无法正常工作
我的设置:
- 本地机器上的ubuntu
- 没有
.htaccess - 默认路由
- 配置:
$config['base_url'] = 'http://localhost/~myuser/ci/';$config['index_page'] = 'index.php';$config['uri_protocol'] = 'AUTO';
- 一个名为 users.php 的控制器具有“listone”方法的类用户
我试着打电话
- http://localhost/~myuser/ci/index.php?users/listone -> 欢迎页面
- http://localhost/~myuser/ci/index.php/users/listone -> 404
我配置了不同的路由,默认使用 users/listone。那是有效的,但是我无法访问其他方法。
我做错了什么?我尝试按照教程进行操作,但它似乎不像描述的那样工作。
编辑: 即使在 base_url 末尾有一个斜杠,它也不起作用,当为空时也不起作用
当我调用 index.php/users/listone 时,我得到了一个 server 404,而不是 CI 拥有的那个。
控制器:添加了一个索引方法。 - 无法到达
<?php
class Users extends CI_Controller {
public function listone($page = 'listall')
{
echo $page;
}
public function index()
{
echo 'listone';
}
}
【问题讨论】:
-
等等我错过了什么:
users/listone在routes.php中设置为default_controller时有效吗?我们能看到那个控制器吗?缺少的base_url斜杠肯定需要修复,但不应影响路由。 -
啊哈,一个 server 404。这很重要,但也很奇怪。看看
print_r($_SERVER)是否有任何有用的信息。 -
请发布您的路由配置
-
如问题中所说:我有默认路由。´ $route['default_controller'] = "welcome"; $route['404_override'] = '';'
-
要使
http://localhost/~myuser/ci/index.php/users/listone工作,您仍然需要在Apache 中启用mod_rewrite,并且您可能还需要设置RewriteBase /home/myuser/ci/(最好在您的CI 目录中使用.htaccess)。