2013-02-04 36 views
1

我是Zend2的新手。我不知道如何摧毀特定的會話。zend2:如何摧毀確切的會議?

$check_username = $session->offsetExists('sess_chk_usr_name'); 
if(empty($check_username)) 
{ 
    $session->offsetSet('sess_chk_usr_name', 'test user'); 
} 

我需要刪除會話sess_chk_usr_name,請幫助。

+0

'$會話級> offsetSet( 'sess_chk_usr_name',NULL);'? –

+0

@Mike:在這裏,您將會話的值分配給null。我需要取消設置sess_chk_usr_name。 – Kathiravan

+0

這不是一個會話,它是會話中的關鍵。銷燬會話將是['session_destroy()'](http://php.net/session_destroy),這將吹走一切。 –

回答

5

我意識到它已被回答,但它被問了很多。 ZF2中的會話容器基本上爲ArrayObjects,標記爲ARRAY_AS_PROPS。這意味着它們的行爲就像一個數組和一個對象,所以您不僅可以使用對象提供的方法來訪問屬性,還可以像數組一樣對它們進行操作(儘管應該注意的是,該函數家族不會「T工作)

塞特斯

$session = new Container('foo'); 

// these are all equivalent means to the same end 
$session['bar'] = 'foobar'; 

$session->bar = 'foobar'; 

$session->offsetSet('bar', 'foobar'); 

吸氣劑

$bar = $session['bar']; 

$bar = $session->bar; 

$bar = $session->offsetGet('bar'); 

isset()函數

$test = isset($session['bar']); 

$test = isset($session->bar); 

$test = $session->offsetExists('bar'); 

未設置()

unset($session['bar']); 

unset($session->bar); 

$session->offsetUnset('bar'); 
0

摧毀特定的會話:\

$session->getManager()->getStorage()->clear('ses_variable'); 

    or 

unset($_SESSION['ses_variable']); 

or 

session_destroy('ses_variable');