Calling Controller in Code igniter Helper file
How can we call Controller in Code igniter Helper File?
The process follows two phases such as-
Phase1: Creating function in load_controller helper file with the name mentioned as load_controller. Also, you need to pass absolute path and create an object of that class file while loading the controller. It will automatically create an instance and behave as per the objectives.
<? php if (!defined(‘BASEPATH’)) exit(‘No direct script access allowed’);
function load_controller($controller, $method=’index’)
require_once(FCPATH . APPPATH ‘controllers/’. $controller. ‘.php’);
return $controller-> $method();
Phase 2: Now you can load the controller. At first you need to load the helper file and then you can load the helper function. As well as, you can pass controller and function that you are wanting in your controller or page.
Answered On 06 Apr at 09:40