2009年6月22日星期一

Re: [fw-mvc] Application resources & order

So this would mean that for my Amz_Application_Resource_Myresource I would call something like below?

class Amz_Application_Resource_Myresource
extends Zend_Application_Resource_ResourceAbstract
{

    public function init()
    {
        $this->getBootstrap()->bootstrap('otherresource');

        // Return myresource so bootstrap will store it in the registry
        return $this->getMyresource();
    }

    public function getMyresource()
    {
        // ...
    }

}

Wkr
Jeroen

On 22 Jun 2009, at 20:06, Hector Virgen wrote:

You can bootstrap any resource on demand by calling $this->bootstrap([resource]); This should help prevent any dependency issues.

Take a look at this section of the documentation for more details:

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

--
Hector


On Mon, Jun 22, 2009 at 10:53 AM, Jeroen Keppens <jeroen.keppens@gmail.com> wrote:
Hi,

Quick question regarding the order application resources are initialized.

Suppose I have in my config file:

resources.myresource.option1 = blah
resources.myresource.option2 = blah
resources.myresource.option3 = blah

This will execute (initialize) my Amz_Application_Resource_Myresource.

I could also use the init in the bootstrap like this:

protected function _initMyresource()
{
       $options = $this->getOptions();
       // do stuff
}

Now, if I add this line to the init, I can force that another resource is loaded/bootstrapped before myresource:

$this->bootstrap("anotherresource");

How can I enforce this with application resource classes that depend on something else? a) another resource class or even b) one initialized by the _init* bootstrap functions.

I hope this question makes sense, I'm a bit groggy of studying for my ZFC tomorrow. Think I'm ODing on ZF. ;-)

Jeroen Keppens
http://blog.keppens.biz



没有评论: