CodeIgniter 设置问题
我正在尝试让此 URL 在 codeigniter 安装上运行,今天刚刚安装了最新版本(2.0.2):
http://mydomain.com/pete/ci_test/accounts
所以我已将routes.php中的默认控制器设置为test.php,并且在我的控制器test.php中我有以下代码:
class test extends CI_Controller {
public function index() {
$this->load->view('test');
}
public function accounts() {
$this->load->view('accounts');
}
}
然后我有一个test.php 和 account.php 在我的视图中,当我转到 http:// 时,它会加载 test.php 视图/mydomain.com/pete/ci_test/
但是当我去 http://mydomain.com/pete/ci_test/accounts 它给了我一个 404。我一直在阅读入门指南,它说“默认情况下 CodeIgniter 使用基于段的方法” ,然后给出一个与我正在做的类似的例子。但后来我又读了一点,它说:“默认情况下,index.php 文件将包含在您的 URL 中”。因此,我将其添加到我的 htaccess 文件中(位于 mydomain.com/pete/ci_test/.htaccess):
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
我确保该模块正在 httpd.conf 中加载。它仍然没有进入我的accounts.php 视图。我也尝试过:
http://mydomain.com/pete/ci_test/index.php/ account
但是又是404,我做错了什么?任何建议都会有所帮助,谢谢!
I am trying to get this URL to work on a codeigniter installation, just installed the newest version today (2.0.2):
http://mydomain.com/pete/ci_test/accounts
So I have set my default controller in routes.php to test.php, and inside my controller, test.php I have this code:
class test extends CI_Controller {
public function index() {
$this->load->view('test');
}
public function accounts() {
$this->load->view('accounts');
}
}
and then I have a test.php and an accounts.php inside my views, it loads the test.php view when I go to http://mydomain.com/pete/ci_test/
But when I go to http://mydomain.com/pete/ci_test/accounts it gives me a 404. I have been reading the Getting Started and it says "By default CodeIgniter uses a segment-based approach", and then gives an example similar to what I'm doing. But then I read a little further it says: "By default, the index.php file will be included in your URL" . So I added this into my htaccess file (located at mydomain.com/pete/ci_test/.htaccess):
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I made sure that the module is loading inside httpd.conf. It still doesn't go to my accounts.php view. I have also tried:
http://mydomain.com/pete/ci_test/index.php/accounts
But another 404, what am I doing wrong? Any advice would help, thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了同样的问题,所以我环顾四周。您应该使用此 .htaccess 内容。这对我有用。
I went into the same problem, so i've looked around. You should use this .htaccess content. It worked for me.
您的控制器的类名应为大写:
就访问它而言,网址应为:
编辑 现在我注意到
http://mydomain.com/pete/ci_test/test/accounts
或
http://mydomain.com/pete/ci_test/index.php/test/accounts
Your controller should be uppercase for the class name:
And as far as accessing it, the url should be:
Edit Fixed the subfolder now that I noticed
http://mydomain.com/pete/ci_test/test/accounts
or
http://mydomain.com/pete/ci_test/index.php/test/accounts
默认控制器是在不存在 url 段时加载的控制器 - 就是这样。
如果您希望
/accounts
加载test
控制器和accounts
方法,则必须使用 route 像这样:否则你必须有一个帐户控制器或通过
/test/accounts/< 访问它/代码>
Default controller is what loads when there are no url segments present - that's it.
If you want
/accounts
to load thetest
controller andaccounts
method, you'll have to use a route like this:Otherwise you'll have to have an accounts controller or access it through
/test/accounts/
onteria_ 是正确的,您的控制器应该是大写的。这不是要求,而是“最佳实践”。
但是,我认为控制器的命名与子文件夹的名称会让人们感到困惑。看起来您的安装位于名为
ci_test
的文件夹中。在这种情况下,要访问它,URL 应为http://mydomain.com/pete/ ci_test/test/accounts
或
http://mydomain.com/pete /ci_test/index.php/test/accounts
onteria_ is correct that your controller should be uppercase. This is not a requirement, but rather a "best practice."
However, I think the naming of your controller vs. the name of the subfolder is throwing people off. It looks like you have your installation inside a folder called
ci_test
. In that case, to access it, the URL should be eitherhttp://mydomain.com/pete/ci_test/test/accounts
or
http://mydomain.com/pete/ci_test/index.php/test/accounts