为什么我不能从其他文件访问 symfony 会话变量? [英] Why can't I access symfony session variables from other files?
问题描述
我有一个使用 symfony 框架构建的网络应用程序.
I have an web app built with symfony framework.
我想合并一个 symfony 应用程序和一个 codeigniter 应用程序,而无需仅使用一个框架创建一个新应用程序.所以如果用户在 symfony 中登录,它也会在 codeigniter 中登录
I want to merge an symfony app and an codeigniter app without creating a new application using only one framework. So if the user is loged in in symfony it will also be loged in codeigniter
现在我只是想从另一个 php 文件访问这个 symfony 应用程序的会话变量,但是 $_SESSION
变量是空的.
Now i am just trying to access session variables of this symfony app from another php file, but the $_SESSION
varible is empty.
(当我在这个新文件中打印它时,当我在 symfony 文件控制器或视图"中打印它时,它会正确显示会话变量).
(When I print it in this new file, when I print it in symfony files 'controllers, or views' printing it shows session variables correctly).
这个newfile.php
与symfony app在同一个域中,与symfony的index.php
、admin.php
在同一个文件夹中.
This newfile.php
is in the same domain with symfony app,in the same folder with symfony's index.php
, admin.php
.
有人可以帮我做这个吗?
Can anybody help me do this?
推荐答案
对于 Symfony2 使用composer"时的解决方案是
For Symfony2 when using "composer" the solution is
require_once 'PATH_TO_LIB/vendor/autoload.php';
$symfonySession = new \Symfony\Component\HttpFoundation\Session\Session($app['session.storage']);
$symfonySession->has('someVariable');
...
这篇关于为什么我不能从其他文件访问 symfony 会话变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!