伙计们我想创建一个命令控制台,它会使会话过期或破坏Symfony 2中的会话?这是我的初始代码,它不起作用:(谢谢希望你能帮助我
public function configure()
{
$this
->setName('pat:session:delete')
->setDescription('Delete a existing session')
->addArgument('session_id', InputArgument::REQUIRED, 'The ID of session that will destroy')
;
}
public function execute(InputInterface $input, OutputInterface $output)
{
$sessionId = $input->getArgument('session_id');
$sessionQuery = SessionQuery::create()
->filterById($sessionId)->findOne()->toArray();
$session = $this->getContainer()->get('session');
//Option 1
$session->migrate($destroy = false, $lifetime = null);
//Option 2
$session->invalidate();
//Option 3
$session->getMetadataBag()->stampNew(1);
//Option 4
$session->remove($sessionQuery["Id"]);
}
答案 0 :(得分:0)
//通过控制器(Symfony 2.6+)注销
$这 - >获得( 'security.token_storage') - > setToken(空); $这 - >获得( '请求') - >的getSession() - >无效();