-Hector
On Wed, May 6, 2009 at 10:40 AM, Matthew Weier O'Phinney <matthew@zend.com> wrote:
-- Hector Virgen <djvirgen@gmail.com> wrote
(on Wednesday, 06 May 2009, 10:13 AM -0700):
> I'm going through the documentation on Zend_Application and am trying to figureThe documentation is slightly off in that regard.
> out how to pass options from my application.ini file to my protected _init*
> methods.
>
> According to the docs: "First, you can write methods prefixed with _init to
> specify discrete code to bootstrap. These methods will be called by bootstrap
> (), and can also be called as if they were public methods: bootstrap<resource>
> (). They should accept an optional array of options."
>
> My question is about that last sentence. Where does this array of options come
> from?
Since the method is local to the bootstrap class, you can simply pull
options from those registered with your bootstrap:
protected function _initFoobar()
{
if (!$this->hasOption('foobar')) {
// no options; nothing to configure
return;
}
$options = $this->getOption('foobar')
// do something...
return $foobar;
}
The API defines hasOption(), getOption(), getOptions(), and
setOptions() for accessing the options.
Now, in your example below, you'll need to do two things. First, the
"resources." key is primarily for use with plugin resources; the options
below it are passed to those plugin resources on initialization. As
such, you should move them up a notch in the hierarchy:
autoload.includeFileCache = ...
Second, you can then do as I noted above, only substibute 'autoload'
where I have 'foobar'. From there, you can continue initializing the
autoloader.
--
> I've tried updating my application.ini file with some options like this:
>
> ; autoload
> resources.autoload.includeFileCache = APPLICATION_PATH "/data/
> pluginLoaderCache.php"
>
> Then in my Bootstrap.php file I added this method:
>
> protected function _initAutoload(array $options = array())
> {
> Zend_Debug::dump($options); // empty array
> Zend_Debug::dump($this->_options['resources']['autoload']); // option
> exists
> }
>
> Is there a way to read that config setting without manually traversing $this->
> _options? I'm using the 1.8.0 tag of ZF.
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论