I started with CodeIgniter today, and I’m following the beginner tutorial from phpacademy. Right now I got an odd problem, I got the following very simple controller:
<?php if ( ! defined('BASEPATH')) exit("No direct script access allowed");
class Site extends CI_Controller {
public function index()
{
}
public function home()
{
$this->load->view("view_home", $data);
}
function about()
{
$data['title'] = "About!";
$this->load->view("view_about", $data);
}
function test()
{
echo "test";
}
}
It always loads the index function fine. When I test it, it echoes whatever I want it to echo. But when I call the other functions nothing happen.
I didn’t set up my .htacces yet, but when I visit the following address: localhost:8899/index.php/site/home
it doesn’t load the home function. same goes for the other function (“about” and “test”);
When I call one of the functions (“home”, “about” and “test”) from within the index() function it does call it how it should:
class Site extends CI_Controller {
public function index()
{
$this->home();
}
public function home()
{
$this->load->view("view_home", $data);
}
I’m not sure what is going wrong here. Hopefully, someone can guide me in the right direction!
My Routes:
<?php if ( ! defined('BASEPATH')) exit("No direct script access allowed");
$route['default_controller'] = "site";
$route['404_override'] = '';
localhost:8899/index.phpandlocalhost:8899/index.php/site/indexwork for loading your index method? It may also be worthwhile posting the contents of your routes.php file.localhost:8899/index.php/site/indexalso loads my index method just finehttp://localhost:8899/index.php/and see if it makes a difference. If not, add the contents of your routes.php to your question, as it most likely needs changing.localhost:8899/index.php/site/about? Do you get a white screen? If you add an echo 'test'; to youraboutmethod, does it not get displayed?config.phpi had$config['uri_protocol']= 'QUERY_STRING'. That was the problem all along. I'm not quite sure why it was not onAUTOas it should Thanks for your time and help anyway!