Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any super controller or global controller in Codeigniter

I want to call a function in a controller (say controller_a) from another controller (say controller_b)

Please help me ..

like image 287
SG_ Avatar asked Mar 11 '12 05:03

SG_


People also ask

What is the default controller in CodeIgniter?

Defining a Default ControllerCodeIgniter can be told to load a default controller when a URI is not present, as will be the case when only your site root URL is requested. To specify a default controller, open your application/config/routes. php file and set this variable: $route['default_controller'] = ' Blog ';

What is controller in CodeIgniter?

A controller is the intermediary between models and views to process HTTP request and generates a web page. All the requests received by the controller are passed on to models and views to process the information. It is the center of every request on your web application.

What is $this in CodeIgniter?

In terms of codeigniter: You'll notice that each controller in codeigniter extends the base controller class. Using $this in a controller gives you access to everything which is defined in your controller, as well as what's inherited from the base controller.

What is the use of constructor in CodeIgniter?

Constructor is a function that is automatically called when instantiated. this function helps us to intialize the things that we are going to need frequently in our code like when we have to load the models of helpers like form e.t.c.


1 Answers

Shared controller functions should usually be in an extended controller class:

<?php
/**
 *  File: /application/core/MY_Controller.php
 */
class MY_Controller extends CI_Controller {

    /**
     * Prefix with an underscore if you don't want it
     * publicly available through URI-routing
     */
    public function _some_shared_method()
    {
        // some common operation here
    }

}

Then, make sure any controller that needs to use this function extends MY_Controller.

like image 180
landons Avatar answered Nov 15 '22 04:11

landons