Syl*_*inB 6 php session symfony
在最新的Symfony 2版本(使用FOSUserBundle和SonataUserBundle)上,我试图让当前用户在我的新实体控制器中预填充表单.
在mycontroller.yml上:
my_controller_new:
pattern: /new
defaults: { _controller: "MySiteBundle:MyController:new" }
Run Code Online (Sandbox Code Playgroud)
在MyController.php上:
public function newAction()
{
$user = $this->getUser();
// ...
}
Run Code Online (Sandbox Code Playgroud)
但是当我打电话时$this->getUser(),该方法返回null.即使我已登录(我可以/profile毫无问题地访问和更新我的用户信息)
然后我试着检查会话是否已启动:
public function newAction()
{
var_dump($this->get('session')->isStarted());
// ...
}
Run Code Online (Sandbox Code Playgroud)
它返回false.这有什么不对?
小智 0
public function newAction() {
$session = $this->getRequest()->getSession(); // Get started session
if(!$session instanceof Session)
$session = new Session(); // if there is no session, start it
$value = $session->getId(); // get session id
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1686 次 |
| 最近记录: |