Karl Wong
Karl Wong

Reputation: 605

Global Query Data

There's a part of a code (query) that will be required in all controllers, they will be passed into views for display.

Can I know is there anyway to declare them in just a single file so that I can reference them directly from my view? Without declaring them in each controller's _construct.

I'm using codeigniter3, here's a sample code:

MainController.php

public function index(){
      $data['userCampaign'] = $this->Usermodel->getCampaign();
}

Upvotes: 0

Views: 44

Answers (3)

Keval Rathi
Keval Rathi

Reputation: 986

Create default controller in your project which extends CI_Controller and your all controller extends new controller and in __construct(); function of your new controller you can add this code.

Upvotes: 1

Abdulla Nilam
Abdulla Nilam

Reputation: 38652

No. I don't know there is method like that.

You want call the function in __construct() or you have to declare function in controller and call it back. $this->check_session()

Upvotes: 0

Nitromoon
Nitromoon

Reputation: 378

Declare this function as protected in parent controller class.

Upvotes: 0

Related Questions