Welcome Guest, Not a member yet? Register   Sign In
Simple language selector with sessions
#1

[eluser]Unknown[/eluser]
Looking for something simple in the end I decided to make my own code (CI version 2.0.1):

The Controller:

Code:
<?php
class Language extends CI_Controller {

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

    function set($language) {
        $this->session->unset_userdata('language');
        $this->session->set_userdata('language', $language);      
        redirect('');
    }
}
?>

Sample Controller:
Code:
<?php

class Articles extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->library('session');
        $this->lang->load($this->session->userdata('language'), $this->session->userdata('language'));
    }
}?>

Sample View:

this can change the session for the selected language:
Code:
<?php echo anchor('language/set/spanish', 'EspaƱol') ?>
<?php echo anchor('language/set/english', 'English') ?>


To retrieve a line of the language just use this line:
Code:
$this->lang->line('Facilities')

---------------
I have only been 2 weeks with CI, excuse the bad writing of code you might have, appreciate if you contribute with your comments xD




Theme © iAndrew 2016 - Forum software by © MyBB