php - How to change the site language in codeigniter -


i have developed website in codeigniter , want multi-language.

i have followed tutorial working hooks. here hook.php

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

and have created class , placed inside hooks folder.

class langswitch extends ci_controller {     public function __construct()     {         parent::construct();         $this->load->helper('url');     }     function switchlanguage($language="")    {        $language=($language!="") ? $language:"english";         $this->session->set_userdata('site_lang',$language);        redirect(base_url());    } } 

and here file placed inside hooks folder

class languageloader {     function initialize()     {         $ci=&get_instance();         $ci->load->helper('language');         $site_lang=$ci->session->userdata('site_lang');         if($site_lang)         {             $ci->lang->load('dari','dari');         }         else         {             $ci->lang->load('english','english');         }     } } 

and here view file.

<a href='<?=site_url('langswitcher/switchlanguage/english')?>'>english</a> 

and says "the requested page not found ". can body find happening ?

your controller called langswitch in url, generate "langswitch er" in site_url(...). if don't have routes set it's typo there.

also, if($site_lang) condition looks wrong in languageloader. maybe wanted if ($site_lang == "dari") , elseifs other supported languages or switch()


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -