Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何访问codeigniter 3.0中route.php中的会话_Php_Codeigniter_Codeigniter 3 - Fatal编程技术网

如何访问codeigniter 3.0中route.php中的会话

如何访问codeigniter 3.0中route.php中的会话,php,codeigniter,codeigniter-3,Php,Codeigniter,Codeigniter 3,如何访问codeigniter 3.0中route.php中的会话 我的应用程序支持多语言,因此我可以使用会话进行语言更改我的应用程序数据、标签、静态标题语言更改 现在我想扩展我的应用程序 意思是当语言改变的时候url也改变了意思 比如说 http://localhost/test/en/controller/method 当更改spainsh中的语言时,url更改如下 http://localhost/test/es/controller/method 那么我该怎么做呢 请帮助我,谢谢您始

如何访问codeigniter 3.0中route.php中的会话

我的应用程序支持多语言,因此我可以使用会话进行语言更改我的应用程序数据、标签、静态标题语言更改

现在我想扩展我的应用程序

意思是当语言改变的时候url也改变了意思

比如说

http://localhost/test/en/controller/method
当更改spainsh中的语言时,url更改如下

http://localhost/test/es/controller/method
那么我该怎么做呢


请帮助我,谢谢

您始终可以访问
$\u会话
变量。但是,我不确定它是否与CodeIgniter会话库兼容

session_start();

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

就我所知,您正在使用Codeigniter的会话数据作为标识来指示lang及其相关数据

Codeigniter使用了类似的超全局会话维护方式,比如使用session\u start()和$\u session。 但建议不要在控制器之外的任何地方使用会话数据

尝试编写一个扩展到所有控制器的超级控制器

            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

}
或者,您也可以在中的Codeigniter中使用多语言支持


或者,如果您仍希望在routes.php中使用会话。正如Alexander所说,您可以尝试使用标准的PHP方式。但我怀疑它是否能正常工作。

对于类似这样的事情,请查看codeigniter挂钩,它们可能会有很大的帮助,并且似乎正是您真正需要的。