Reputation: 231
I am using Codeigniter framework to develop a website. I am currently working on home.php
view under the view folder. I need to use UserInfo()
function which is inside one of the controllers. Any suggestion how to access that function?
class Welcome extends CI_Controller {
public function UserInfo(){
$this->load->model('model_user');
$data['title'] = 'Users';
$data['users'] = $this->model_user->getUser();
$this->load->view('template/users', $data);
}
}
Upvotes: 0
Views: 77
Reputation: 2587
As You want to call controller function in other controller.In codeigniter
App
folder core
folder exists you make a custom core controller
and all other controllers extend with your custom controller
In your Custom Core controller
class CustomCore extends CI_Controller
{
/* ---YOUR FUNCTION IN CUSTOMCORE---- */
public function mycorefunc()
{
//Do something
}
}
and your all other controllers extend with custom core
class YourController extends Customcore
{
function controllerfunction()
{
$this->mycorefunc();// Call corefunction
}
}
Upvotes: 0
Reputation: 38584
You cant call controller method inside another controller. Its No Way to do it.
You have two way to resolve this issue
redirect('welcome/UserInfo')
if you just need to call the functionUpvotes: 1