开发者

CodeIgniter Setup Question

开发者 https://www.devze.com 2023-03-06 08:28 出处:网络
I am trying to get this URL to work on a codeigniter installation, just installed the newest version today (2.0.2):

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_Co开发者_开发问答ntroller {

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!


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]


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


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/


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

0

精彩评论

暂无评论...
验证码 换一张
取 消