Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load a controller from another controller in codeigniter?

I want to load a controller from a function in another controller because the library I integrated to my project I don't want to load it to the controller because I want to keep it clean and related.

I tried using modules but I still had to put controller in the url like

http://example.com/maincontroller/function
http://example.com/othercontroller/function

I have default controller so I can load http://example.com/function so how could I access the controller from a function from main so I don't have to put the controller in the url.

I'm still willing to use HMVC if I can load the controller function from the main controller function.

like image 215
Luis Liz Avatar asked Jan 04 '13 22:01

Luis Liz


People also ask

Can we call one controller from another controller in CodeIgniter?

Codeigniter (and MVC in general) aren't designed to work this way. Controllers don't call other controllers. If you find yourself needing to do that it's likely an indicator that your app architecture needs some refactoring.

How can we call one controller function from another controller in PHP?

Show activity on this post. Create new Helper (e.g PermissionHelper. php ) then move the funtion to it and call it where you want using : PermissionHelper::permission();


1 Answers

yes you can (for version 2)

load like this inside your controller

 $this->load->library('../controllers/whathever'); 

and call the following method:

$this->whathever->functioname(); 
like image 175
Geomorillo Avatar answered Sep 21 '22 02:09

Geomorillo