Reputation: 2163
I am really stuck with this problem
in CodeIgniter i have controller named user.php
and it has two function getUser() and save()
when I try to call http://localhost/CodeIginter/index.php/user/save
it always call getUser function why ?
class user extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function getUser()
{
$this->load->model('usermodel');
$data['query'] = $this->usermodel->get_last_ten_entries();
$this->load->view('users',$data);
}
function save()
{
$this->load->model('usermodel');
$this->usermodel->insert_entry();
$this->load->view('users');
}
}
my .htaccess file contain
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
and i am also unable to load another controller that is helloworld.php
Upvotes: 1
Views: 4586
Reputation: 41
step-1: change this .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /your_folder_name/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
step-2: application/config/config.php
$config['base_url'] = 'full_path';
$config['index_page'] = '';
step-3: application/config/routes.php
$route['default_controller'] = "user";
step-4: user class add this function
public function index(){
}
Upvotes: 2
Reputation: 37711
Controller names must be capitalized. So, User
instead of user
.
class User extends CI_Controller
class Helloworld extends CI_Controller
...
The file names remain in lowercase though.
Other than that, everything seems fine.
Upvotes: 1
Reputation: 1179
There could be 2 problems:
1. Missing route :
Goto application/routes.php
$route['user'] = "user";
2.You need to make function public if you want to call it from outside in url.
So,
class user extends CI_Controller
{
function __construct()
{
parent::__construct();
}
public function getUser()
{
$this->load->model('usermodel');
$data['query'] = $this->usermodel->get_last_ten_entries();
$this->load->view('users',$data);
}
public function save()
{
$this->load->model('usermodel');
$this->usermodel->insert_entry();
$this->load->view('users');
}
}
Hope your problem is solved now:)
Upvotes: 1
Reputation: 34175
It seems you are missing a route. Add the following line to your routes.php
file
$route['user'] = "user";
And now it should be working as expected
Upvotes: -3