1
關於如何在symfony2中請求/獲取會話,還有其他方法嗎?除了打開一個服務容器和通過請求?感謝獲取/請求Session Symfony2的另一種方法是什麼?
我創建一個會話管理器,在那裏將通過命令控制檯創建一個會話
關於如何在symfony2中請求/獲取會話,還有其他方法嗎?除了打開一個服務容器和通過請求?感謝獲取/請求Session Symfony2的另一種方法是什麼?
我創建一個會話管理器,在那裏將通過命令控制檯創建一個會話
您可以在會話直接注入您的SessionManager:
創建會話管理器:
<?php
namespace Acme\YourBundle\Manager;
use Symfony\Component\Session/SessionInterface;
class SessionManager
{
/**
* The session
*
* @var SessionInterface
*/
private $session;
/**
* @param SessionInterface
*/
public function __construct(SessionInterface $session)
{
$this->session = $session;
}
}
並將其聲明爲服務:
services:
# Session manager
acme_your_bundle.session_manager:
class: Acme\YourBundle\Manager\SessionManager
arguments:
session: "@session"
你可以看看Session的api,它會幫助你完成。
謝謝你sohhhhhhhh! :) – user2533808
我很高興它有幫助! – Mick