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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:25:24+00:00 2026-05-27T22:25:24+00:00

I have an array of language names I use repeatedly throughout my application. What’s

  • 0

I have an array of language names I use repeatedly throughout my application. What’s the best way to do that. I tried this library, following an example on here.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class Config extends CI_Controller
    {
        public $languages = '';
        public $languages_en = '';

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

            $this->languages = array('ar', 'cn', 'fr', 'de', 'it', 'jp', 'kr', 'pl', 'pt', 'ru', 'es', 'sk');

            $this->languages_en = array('ar', 'cn', 'fr', 'de', 'it', 'jp', 'kr', 'pl', 'pt', 'ru', 'es', 'sk', 'en');  
        }
    }
?>

And then I tried loading the library and calling the variable. But I get an error that the action I requested is not allowed.

Is this the best way to do this? Or is there a better way to create a global variable in CI? By the way, is the name of my class an issue?

  • 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-27T22:25:25+00:00Added an answer on May 27, 2026 at 10:25 pm

    Yes, Config would not be an allowed class name as CI already has a Config class.

    However, I would create a config file to hold these arrays and just load that file when needed.

    Docs: http://ellislab.com/codeigniter/user_guide/libraries/config.html

    So in your config file /application/config/languages.php, you would put this:

    $config['languages'] = array('ar', 'cn', 'fr', 'de', 'it', 'jp', 'kr', 'pl', 'pt', 'ru', 'es', 'sk');
    
    $config['languages_en'] = array('ar', 'cn', 'fr', 'de', 'it', 'jp', 'kr', 'pl', 'pt', 'ru', 'es', 'sk', 'en');
    

    Then, in your controllers, you can do this:

    $this->config->load('languages');
    $lang = $this->config->item('languages');
    $lang_en = $this->config->item('languages_en');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ok I have two strings. (I use this for a language library system to
I have an array that holds the names of languages in spanish: $lang[ko] =
Possible Duplicate: Sizeof an array in the C programming language? I have an array
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
PROBLEM I have a nested PHP array that I need to populate from flat
I have an array of names but can't seem to make the comparison work.
I have a Profile form that inherits from sfGuardRegisterForm I have these fields: $this->useFields(
I am new to this fancy language called Scala. I have enough (I guess)
I have three dimensional array of data that is generated from web server logs

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.