2009年5月6日星期三

Re: [fw-mvc] Zend_Application and bootstrap options

I've decided to "promote" my _initAutoload method to a resource plugin. I've created the class My_Resource_Autoload and saved it in library/My/Resource/Autoload.php. 

What is the best way to register the prefix path for "My_Resource_"? The documentation is a little vague on how to do it:

As long as you register the prefix path for this resource plugin, you can then use it in your application. 

http://framework.zend.com/manual/en/zend.application.theory-of-operation.html#zend.application.theory-of-operation.resources

Thanks again!

-Hector


On Wed, May 6, 2009 at 10:43 AM, Hector Virgen <djvirgen@gmail.com> wrote:
Thanks, Matthew. That makes things much easier.

-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 figure
> 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?

The documentation is slightly off in that regard.

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/



没有评论: