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 833183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:28:38+00:00 2026-05-15T04:28:38+00:00

I have got a problem with my codeigniter library. To transform database data into

  • 0

I have got a problem with my codeigniter library. To transform database data into a navigation and have active elements and such like I build a library class CI_Navigation().
It works perfectly fine, I just have one problem.

Often on webpages one has corresponding but separated navigations e.g. a main navigation at the top and a subnavigation on the side. To get around that I can initialize my class with a parameter telling it which levels this navigation is to hold.
I would for example do something like this.

$this->load->library('Navigation');

$main = $this->navigation->build( array('levels'=>array(0)) );
$sub = $this->navigation->build( array('levels'=>array(1,2)) );

As you might expect it does not work, because the data in the class stays the way it was assigned by the first call of build.

Sadly enough in CodeIgniter Libraries are singletons (right? that’s what I read). So I can not initialize it twice like:

$this->load->library('Navigation','','main');
$this->load->library('Navigation','',sub);

Do you have any idea how I can overcome this problem.

It should work if I would use arrays for the variables used in the class right?
E.g. for the options instead of using $this->option I would have to dynamically create $this->$option[0], $this->$option[1].

Does this work? I can not test it at the moment but will do so tonight. But this is not a really elegant way, so is there a better way to solve this? Is there any way i could initialize the library multiple times?

Thanks in advance guys.

  • 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-05-15T04:28:39+00:00Added an answer on May 15, 2026 at 4:28 am

    If you want to stick the strict CI library implementation, then I would suggest that you make your class parameters an array of configurations; and then specify the configuration you want to use in your ‘build’ function.

    $options = array
    (
      'main' => array('level' => 0),
      'sub' =>array('level' => 1)
    );
    
    $this->load->library('navigation', $options);
    
    $main_nav = $this->navigation->build('main');
    $sub_nav = $this->navigation->build('sub');
    

    But I often revert to standard objects for this sort of thing:

    $a_navigator = new Navigation($options_a);
    $b_navigator = new Navigation($options_b);
    
    $a_tree = $a_navigator->build();
    $b_tree = $b_navigator->build();
    
    unset($a_navigator);
    unset($b_navigator);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 478k
  • Answers 478k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use sets: require 'set' list_1 = open(filename_1).read.split.to_set list_2 = open(filename_2).read.split.to_set… May 16, 2026 at 5:29 am
  • Editorial Team
    Editorial Team added an answer First, make sure you have a backup Right click on… May 16, 2026 at 5:29 am
  • Editorial Team
    Editorial Team added an answer What about the "JFDI" pattern? BEGIN TRY INSERT etc END… May 16, 2026 at 5:29 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.