【发布时间】:2018-01-08 16:00:27
【问题描述】:
我在 \web 文件夹中创建了一个 php 文件(这意味着在应用程序之外对吗?),我在应用程序内的会话中设置了一个变量(在控制器操作中),但我无法在应用程序(在外部 php 文件中)。我的会话总是空的。
这是我设置会话的控制器操作
*/
public function questionnaireConfigAction($id,Request $request)
{
$em=$this->getDoctrine()->getManager();
$questionTypes=$em->getRepository(QuestionType::class)->findAll();
$questionnaire = $em->getRepository(Questionnaire::class)->find($id);
$session = new Session();
$session->set('fileContext',['questionTypes'=>$questionTypes,'questionnaire'=>$questionnaire]);
return $this->render('questionnaires/questionnaireConfig/config.html.twig',
['questionTypes'=>$questionTypes,
'questionnaire'=>$questionnaire]);
}
这是外部文件
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Response;
use AppBundle\twigExtentions\filesLoader;
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
$loader = require __DIR__.'/../app/autoload.php';
$request = Request::createFromGlobals();
$session = new Session();
$session->start();
dump($session->get('fileContext')); /*get nothing here */
【问题讨论】:
-
您是否验证过会话 ID 是否可用于您的第二个脚本...?
-
与 $session->getId() ?是的,我得到了第一个脚本的相同 id