Reputation: 195
I am having problems with codeigniter 3, I am using netbeans as my IDE and wampserver. I was able to browser successfully to 'localhost/ci_test/' (ci_test is the name of the project/website') and it served me the default welcome.php controller, however I tried a 2nd controller inside the CI controller folder called 'Test.php', with the following content:
<?php
class Test extends CI_Controller {
public function index() {
echo "This is default function.";
}
public function hello() {
echo "This is hello function.";
}
}
?>
then when i tried to browse to that controller: with the following url: http://localhost/ci_test/index.php/test it served me my welcome.php (which is not what I wanted),
then I tried this url: http://localhost/ci_test/test.php
and I got a response:
Not Found
The requested URL /ci_test/test.php was not found on this server.
Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80
I don't understand what am I missing here...
Note: I did not change the .htacess files that were provided by codeigniter, and left them as is(maybe the problem there).
I only changed the following things in CI:
application/config/config.php:
$config['base_url'] = 'http://localhost/ci_test/';
$config['index_page'] = ''
$config['uri_protocol'] = 'PATH_INFO';
I hope someone can help here :)
EDIT: I have read the first 4 answer's and it still doesn't work
EDIT2: so after I decided to give up, I noticed that my apache server did not have ' mod_rewrite' ON, so i turned it on tried again the same project and it still did not work, Then I decided to create a new project from scratch and with CI, I added new controller and everything works well now. this is lol... Thank you very much for all those who tried to help me :)
Upvotes: 0
Views: 538
Reputation: 5507
This is a rushed quick answer... If you are using WAMPServer, check that it hasn't set MultiViews in either your httpd file or the vhosts file if you are using that.
Upvotes: 0
Reputation: 1584
welcome controller
<?php
class Welcome extends MY_Controller
{
public function index()
{
$this->load->view('welcome');
}
}
welcome view
<a href="<?php echo base_url('test'); ?>">Test Page</a>
test controller
<?php
class Test extends MY_Controller
{
public function index()
{
$this->load->view('test');
}
}
test view
<h1>Test Page</h1>
The views must be named test.php and welcome.php and placed into the views folder.
Let us know how you get on.
Have a look at the routes.php file in the config folder
Change $route['default_controller'] = 'welcome';
to
$route['default_controller'] = 'test';
See if that works
If you get an error saying it can't find the page look at the address bar if it is like this
http://localhost/ci_test/test
try changing it to this
http://localhost/index.php/ci_test/test
Upvotes: 1
Reputation: 157
You need to access that Test Controller directly then you need to add .htaccess file in the project root.. here is the .htaccess file for avoiding index.php in codeigniter
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
if you add this .htaccess file in the root your problem will resolved..
also don't need to add extention in your url (http://localhost/ci_test/test.php) , this is wrong
http://localhost/ci_test/test
this is enough to load your controller
Upvotes: 1
Reputation: 5507
Out of the box, codeigniter uses the url . com/controller/method.
You have created a Test controller called Test.php. To access it you would use...
http://localhost/ci_test/test
You Do Not put a .php on the end.
Upvotes: 0