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?
Yes,
Configwould not be an allowed class name as CI already has aConfigclass.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:Then, in your controllers, you can do this: