Reputation: 1702
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'] = '';
Upvotes: 0
Views: 3650
Reputation: 93
If somebody came across this since no solutions above worked, ok you can try these steps where i got the thing worked (local with xampp):
base_url
in config.php
into http://localhost/application-name/
index_page
(the default value should be index.php
)index.php
is thereMake .htaccess
file in there and write into that these:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Upvotes: 1
Reputation: 4024
i would make sure the controller class has a constructor to load the base codeigniter base classes.
function __construct()
{
parent::__construct();
}
in each controller class tells your class to use the code igniter system. if this is not present it won't know to how to load these functions.
Just to be clear, make sure it calls the other methods by url/site/about etc... Also, have you got php errors displaying on you development server?
Upvotes: 0