views:

50

answers:

2

Hi,

Does Zend_Registry live until next user request?

I put this code in the end of index.php file in zend project:(The code inside existing zend website)

Trial code:

    //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>';
    }

Results after each click to home page:

Zend_Registry was unset

Thanks

+9  A: 

No, Zend_Registry is just for the current request. If you want data to persist between requests you'd need to store it in the session.

Tim Fountain
A: 

Not to answer your question but it's better to write it like this I think

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>';
}
boosis
its bad use exception in php very slow
Yosef
Never use exceptions for control flow.
smack0007