2010-10-10 24 views
1

是否Zend_Registry直到下一個用戶請求才會生效?Zend_Registry是否存在直到下一個用戶請求?

我把這個代碼在Zend的項目index.php文件的末尾:(現有的Zend網站中的代碼)

試用代碼:每次使用後

//end of index.php file 
    Bootstrap::run(); 
    //trial for find out the life of Zend_Registry. 
    $registry = Zend_Registry::getInstance(); 
    if (!isset($registry['index1'])) { 
     Zend_Registry::set('index1', 'value7'); 
     echo '<h1>Zend_Registry was unset</h1>'; 
    } else { 
     echo '<h1>Zend_Registry was set</h1>'; 
    } 

結果點擊主頁:

合適的詞彙被清除的

謝謝

回答

9

不,Zend_Registry僅適用於當前請求。如果您希望數據在請求之間持續存在,則需要將其存儲在會話中。

-2

不回答你的問題,但最好還是把它寫這樣我覺得

try{ 
    Zend_Registry::get('index1'); 
    echo '<h1>Zend_Registry was set</h1>'; 
} catch (Exception $e) { 
    Zend_Registry::set('index1', 'value7'); 
    echo '<h1>Zend_Registry was unset</h1>'; 
} 
+0

它不好用例外的PHP很慢 – Yosef 2010-10-10 10:51:58

+0

切勿使用控制流異常。 – smack0007 2010-10-10 18:00:41

相關問題