Making It Easier to Access The Options in Zend Framework
If you use the application.ini config file to store differences in production and testing environments (I highly recommend it) it can be annoying to access the settings. Getting the Bootstrap first and then retrieving the settings file can be annoying and error prone.
It turns out there is a much simpler way to handle this. First add the following to your Bootstrap file:
protected function _initSaveSettings(){
Zend_Registry::set('options', $this->getOptions());
}
Then whenever you need the options you can do the following:
$options = Zend_Registry::get('options');
$setting = $options['settingName'];
Or if you're using PHP 5.4+ (I've already been burned by this twice so don't do it if you can't be sure) you can do this:
$setting = Zend_Registry::get('options')['settingName'];
Scott Keck-Warren
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.
Top Posts
- Working With Soft Deletes in Laravel (By Example)
- Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
- Upgrading to Laravel 8.x
- Get The Count of the Number of Users in an AD Group
- Multiple Vagrant VMs in One Vagrantfile
- Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
- Changing the Directory Vagrant Stores the VMs In
- Accepting Android SDK Licenses From The OSX Command Line
- Fixing the 'Target class [config] does not exist' Error
- Using Rectangle to Manage MacOS Windows