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

  • Home
  • SEARCH
  • 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 8603479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:20:04+00:00 2026-06-12T02:20:04+00:00

I have several $data which are called in almost all functions in controller. Is

  • 0

I have several $data which are called in almost all functions in controller. Is there a way to create this $data in __construct function and combine them with $data in called function? Example:

function __construct() {
        parent::__construct();

        $this->load->model('ad_model', 'mgl');
        $this->load->model('global_info_model', 'gi');
        $this->load->model('user_model', 'um');        
        $this->load->library('global_functions');
        $this->css = "<link rel=\"stylesheet\" href=\" " . CSS . "mali_oglasi.css\">";
        $this->gi_cat = $this->gi->gi_get_category();
        $this->gi_loc = $this->gi->gi_get_location();        
        $this->gi_type = $this->gi->gi_get_type();       
        }

    function index() {     
        $count = $this->db->count_all('ad');        
        $data['pagination_links'] = $this->global_functions->global_pagination('mali_oglasi', $count, 2);

        $data['title'] = "Mali Oglasi | 010";
        $data['oglasi'] =  $this->mgl->mgl_get_all_home(10);
        $data['loc'] = $this->gi_loc;
        $data['cat'] = $this->gi_cat;
        $data['stylesheet'] = $this->css;
        $data['main_content'] = 'mali_oglasi';

    $this->load->view('template',$data);
    }

If I want to put $data[‘loc’], $data[‘cat’] and $data[‘stylesheet’] in __construct I will have to call $this->data in $this->load->view(‘template’,$data);

Is there a way to combine this two?

  • 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-12T02:20:05+00:00Added an answer on June 12, 2026 at 2:20 am

    Add a private member to your controller and set it in the constructor as you need it:

    private $data;
    
    function __construct() {
        ...
        $this->data = array(...);
        ...
    }
    

    Then you can access this private member in all of your controllers actions inside the same controller class.

    You can merge two arrays using the array union operator (+)Docs:

    $data = $this->data + $data;
    

    See as well: PropertiesDocs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several worksheets which have different data but organized in the same way
I have several similar user controls which display listviews of respectively different data entities.
I have several objects set up in Core Data, one of which is Deck
I have a DataTable which I select from database (Well, these data cross several
I have several data that looks like this: Vector1_elements = T,C,A Vector2_elements = C,G,A
I have a function called processXML on the timeline (yes, I know now...) which
I have written an importer which copies data from a flat table into several
I have a directory called /user/local/ inside which i have several files of the
I have several complex data structures like Map< A, Set< B > > Set<
I have several Core Data model version that I have added to my .xcdatamodeld

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.