Welcome Guest, Not a member yet? Register   Sign In
Slug from database available on all pages through lang CodeIgniter
#1

I have a table on my database from where I get some slug texts:

art_and_culture
business_and_financial
auto_and_moto
and display on my website through

PHP Code:
<?php echo lang($slug_from_database); ?>
I use this method as LanguageSwticher:

http://www.sitepoint.com/multi-language-...deigniter/

So in My_Controller.php I have in construct:

PHP Code:
$this->categories_list $this->categories_model->entries();
    
$list_categories['categories'] = $this->categories_list;
    
$this->data['sidebar_categories'] = $this->load->view('blocks/sidebar_categories'$list_categoriesTRUE); 

and all the categories are available on all pages from my website.

The problem is when I send the categories to the view, the language is not fired up from the LanguageLoader.php controller. LanguageLoader is initialised in hooks.php (post_controller_constructor - see the link example) BEFORE the my_controller construct. If no language no text on echo $slug_from_database. How do you suggest to do?
Reply
#2

Read CI3 Documentation
http://www.codeigniter.com/user_guide/li...guage.html
Keep calm.
Reply
#3

(This post was last modified: 08-15-2015, 04:36 AM by sebastianvirlan.)

You did not read my problem.

I found one solution:

Created:


PHP Code:
       public function LanguageLoader() {

       $site_lang $this->session->userdata('site_lang');
       if ($site_lang) {
           $this->lang->load('message',$this->session->userdata('site_lang'));
       } else {
$this->lang->load('message'$this->config->item('language'));

       }
   

in MY_Controller.php

and call it in the constructor:
PHP Code:
$this->LanguageLoader(); 


and delete


PHP Code:
   $hook['post_controller_constructor'] = array(
   'class' => 'LanguageLoader',
   'function' => 'initialize',
   'filename' => 'LanguageLoader.php',
   'filepath' => 'hooks'
); 


from hooks.php so now I load the language in controller`s construct not with hook. What can you tell me about this?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB