I have an array public variable loaded identically in every controller class that I have. The array variable contains language file to be passed to the view file.
Sample:public $data; $this->data = array('lbl_first_name'=>$this->lang->line('lbl_first_name'));
. As language data goes plenty, so as the content of the array that holds the language file does also. How would I able to put this variable to a library or as a helper then loads it something like $this->load->library('language_data') or $this->load->helper('language_data')
in every controller file? not the array variable with lots of language data anymore to be loaded in each controller I have. Thanks a lot. Sample codes are shown below:
Controller 1:
class Courses extends CI_Controller {
public $data;
public function __construct(){
parent::__construct();
$this->data =array(
//language file for menu item
'dropdown'=>$this->lang->line('dropdown'),
'dropdownedit'=>$this->lang->line('dropdownedit'),
'home'=>$this->lang->line('home'),
'menu_desc'=>$this->lang->line('menu_desc'),
'login'=>$this->lang->line('login'),
'login_desc'=>$this->lang->line('login_desc'),
'teacher'=>$this->lang->line('teacher'),
'logout'=>$this->lang->line('logout'),
'course_occasion'=>$this->lang->line('course_occasion'),
'courses'=>$this->lang->line('courses'),
'student'=>$this->lang->line('student'),
'tennant'=>$this->lang->line('tennant'),
'messages'=>$this->lang->line('messages'),
'sent_messages'=>$this->lang->line('sent_messages'),
//language file for forms
'course_edit_form_desc'=>$this->lang->line('course_edit_form_desc'),
'course_reg_form_desc'=>$this->lang->line('course_reg_form_desc'),
'course_view_list'=>$this->lang->line('course_view_list'),
'view_course_available_list'=>$this->lang->line('view_course_available_list'),
'lbl_course_name'=>$this->lang->line('lbl_course_name'),
'lbl_course_desc'=>$this->lang->line('lbl_course_desc'),
'lbl_tennant_name'=>$this->lang->line('lbl_tennant_name'),
'lbl_public'=>$this->lang->line('lbl_public'),
'lbl_not_public'=>$this->lang->line('lbl_not_public')
);
}
}
Controller 2: (Same as controller 1)
class Occasions extends CI_Controller {
public $data;
public function __construct(){
parent::__construct();
$this->data =array(
//language file for menu item
'dropdown'=>$this->lang->line('dropdown'),
'dropdownedit'=>$this->lang->line('dropdownedit'),
'home'=>$this->lang->line('home'),
'menu_desc'=>$this->lang->line('menu_desc'),
'login'=>$this->lang->line('login'),
'login_desc'=>$this->lang->line('login_desc'),
'teacher'=>$this->lang->line('teacher'),
'logout'=>$this->lang->line('logout'),
'course_occasion'=>$this->lang->line('course_occasion'),
'courses'=>$this->lang->line('courses'),
'student'=>$this->lang->line('student'),
'tennant'=>$this->lang->line('tennant'),
'messages'=>$this->lang->line('messages'),
'sent_messages'=>$this->lang->line('sent_messages'),
//language file for forms
'course_edit_form_desc'=>$this->lang->line('course_edit_form_desc'),
'course_reg_form_desc'=>$this->lang->line('course_reg_form_desc'),
'course_view_list'=>$this->lang->line('course_view_list'),
'view_course_available_list'=>$this->lang->line('view_course_available_list'),
'lbl_course_name'=>$this->lang->line('lbl_course_name'),
'lbl_course_desc'=>$this->lang->line('lbl_course_desc'),
'lbl_tennant_name'=>$this->lang->line('lbl_tennant_name'),
'lbl_public'=>$this->lang->line('lbl_public'),
'lbl_not_public'=>$this->lang->line('lbl_not_public')
);
}
}
Desired output:
Controller 1 and Controller 2:
$this->load->library('language_array');
or
$this->load->helper('language_array');