简体   繁体   中英

how i can access session in route.php in codeigniter 3.0

how i can access session in route.php in codeigniter 3.0

my application is multi language support so i can used session for language change my application data , lable,static captions language change

now i want to extend my application

means when language change that time url also change means

for example

http://localhost/test/en/controller/method

when change language in spainsh that time url change like below

http://localhost/test/es/controller/method

so how i can do this

please help me thanks

You always can access to the $_SESSION variable. However, I'm not sure if it's compatible with CodeIgniter Session library.

session_start();

if(isset($_SESSION['lang']))
{
   // define your routing here
}

Upto the level I understand,You're using Codeigniter's session data as an identity to indicate lang and its associated data..?

Codeigniter uses similar way of superglobal session maintainence like using session_start() and $_SESSION. But It is advised not to use session data anywhere else than that of controllers.

Try writing a Super-controller which extends to all of your controllers .

            class SuperController extends MY_Controller
        {



            public function __construct()
             {
                // Ensure you run parent constructor
                parent::__construct();    
                $this->checkSess();
             }

            public function checkSess() 
           {
              //Your session check and its associated redirects
              //eg. if $this->session->en==1 redirect to eng lang controller



            }

        }

    Class YourController extends SuperController{
    //Your code

}

Or You can use multilang suppport in Codeigniter as of in Codexworld

Or If you want to still use session in routes.php . You can try as of in a standard PHP way as Alexander said.But I doubt whether it works properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM