3
我想創建一個命令控制檯,將在Symfony 2中過期會話或銷燬會話?這是我最初的代碼和它不工作:(謝謝希望你能幫助我如何創建將在Symfony2中過期/銷燬會話的命令控制檯?
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"]);
}