开发者

Zend - Site Configuration Data

For my zend application I need to read from the database some basic configuration data which should be available everywhere. I would like to read them and save it to session so that I wouldn开发者_运维技巧't have to do so for every request. What is the best way I can get that done?

And also I would like to get the data from the 'Model' too and would feel very very uneasy to read from the session within the model.


Are you sure, you want to store such important things in the session? You could also load the data from the database and save them in a file / Zend-Config-Object which exists for a specified time and gets updated than.

Another possibilty is Zend_Registry. This however needs to fetch the data each request.

Why don't you want to fetch the data each request from the database? You could easily use a controller-plugin which gets the job done for you. You write the code once and will never have to do something with that.

// This would be an example plugin-class...
class My_Config_Loader extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch($request)
    {
         // Fetch data here... and save it into $data

         Zend_Registry::set('config', $data);
    }
}

// In your bootstrap...
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new My_Config_Loader());

// Anywhere in your application
$config = Zend_Registry::get('config');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜