CodeIgniter 设置问题

发布于 2024-11-08 00:33:26 字数 1299 浏览 0 评论 0原文

我正在尝试让此 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

指尖微凉心微凉 2024-11-15 00:33:26

我遇到了同样的问题,所以我环顾四周。您应该使用此 .htaccess 内容。这对我有用。

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

I went into the same problem, so i've looked around. You should use this .htaccess content. It worked for me.

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
快乐很简单 2024-11-15 00:33:26

您的控制器的类名应为大写:

class Test extends CI_Controller {

就访问它而言,网址应为:

编辑 现在我注意到

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:

class Test extends CI_Controller {

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

萌面超妹 2024-11-15 00:33:26

默认控制器是在不存在 url 段时加载的控制器 - 就是这样。

如果您希望 /accounts 加载 test 控制器和 accounts 方法,则必须使用 route 像这样:

$route['accounts'] = 'test/accounts';

否则你必须有一个帐户控制器或通过 /test/accounts/< 访问它/代码>

Default controller is what loads when there are no url segments present - that's it.

If you want /accounts to load the test controller and accounts method, you'll have to use a route like this:

$route['accounts'] = 'test/accounts';

Otherwise you'll have to have an accounts controller or access it through /test/accounts/

优雅的叶子 2024-11-15 00:33:26

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 either

http://mydomain.com/pete/ci_test/test/accounts

or

http://mydomain.com/pete/ci_test/index.php/test/accounts

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文