Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8058685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:26:17+00:00 2026-06-05T09:26:17+00:00

In my CI controllers I have these three functions: function _temp ($view,$data=) { $this->load->view(‘temp/nm-header’,$data);

  • 0

In my CI controllers I have these three functions:

function _temp ($view,$data="") {
  $this->load->view('temp/nm-header',$data);
  $this->load->view($view,$data);
  $this->load->view('temp/footer',$data);
}

function _qs($val) {
  return $this->session->userdata($val);
}

function _qp($val) {
  return $this->input->post($val);
}

I would like to have a central controller for this, rather than to have to copy/paste these methods in every controller I have. Will making a library do the trick? If so…

$ci =& get_instance

How do I make this variable above be available in all of the menthods I have in my library class?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:26:18+00:00Added an answer on June 5, 2026 at 9:26 am

    No need to create a library. Instead, create a base controller called MY_Controller for your common methods, and have your other controllers extend from it, like this:

    MY_Controller:

    class MY_Controller extends CI_Controller {
    
        function __construct() {
            parent::__construct();
        }
    
        function _temp ($view,$data="") {
            $this->load->view('temp/nm-header',$data);
            $this->load->view($view,$data);
            $this->load->view('temp/footer',$data);
        }
    
        function _qs($val) {
            return $this->session->userdata($val);
        }
    
        function _qp($val) {
            return $this->input->post($val);
        }
    
    }
    

    Any other controller you want to have access to your common methods:

    class Some_controller extends MY_Controller {
    
        function __construct() {
            parent::__construct();
        }
    
        // _temp(), _qs(), and _qp() are now all available to any controller
        // that extends MY_Controller
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a controller function with these lines: $this->load->view('stdHeader_view'); echo <div class='main'>;
I have a view controller with 6 buttons on it. Each of these buttons
I have an asp.net mvc application with three layers: - data layer with entities
I have 4 UITableView's on my iPAD application. I load the data on them
I'm developing a Grails App. I have about 20 Controllers right now and there
Example: I have a view controller and get rid of it. But there's still
So I have a UIViewController (main application controller is a TabBarController). On this there
I have a table view controller with custom cells. In those cells i added
I have a number of functions in my controller logic and for every one
In the iPhone app I'm currently working on, I'd like two view controllers (I'll

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.