okey_on
okey_on

Reputation: 3006

Circular resource dependency error in Zend

I have a bootstrap class which I want to use to set CSS variables:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initView()
    {
        $this->bootstrap('view');
        ...
        ...
    }
}

But trying to get the view resource fails at the bootstrap('view') stage. I get the error:

... Circular resource dependency detected' in C:\ZendFramework\library\Zend\Application\Bootstrap\BootstrapAbstract.php on line 662
...

Which is strange because this is the procedure that tutorials(and the zend documentation) use. What could be wrong?

Upvotes: 2

Views: 1555

Answers (2)

David Weinraub
David Weinraub

Reputation: 14184

Change the method to something like _initViewStuff() and all will be fine.

The reason is that the bootstrap sequence in Zend_Application_Bootstrap_BootstrapAbstract is as follows:

  1. Your initial call to $app->bootstrap() in public/index.php runs through all _initXxx() methods (@see Zend_Application_Bootstrap_BootstrapAbstract::getClassResourceNames()) and calls $this->bootstrap('xxx') for each Xxx it finds. It will then do a similar thing for all the plugin resources defined by resources.* keys in application.ini (though yours never gets that far, as described below).

  2. The call to bootstrap('view') internally stores a flag that he has started the process to bootstrap a resource called view.

  3. He does a similar thing as (1), looking for a matching _initXxx() method. He find it and attempts to execute $this->_initView()

  4. He notices the flag he set, indicating that he's gonna hit an infinite loop, so he bails out with circular dependency exception.

Typically, for each resource xxx, you bootstrap it using one (but not both, as you have discovered) of the following approaches:

  1. Define an _initXxx() method.

  2. Creating a plugin resource class named something like My_Application_Resource_Xxx (you inform that system that My_Application_Resource_ is a namespace prefix for plugin resources using pluginPaths.My_Application_Resource = /path/to/dir/containing/plugin in application/configs/application.ini)

Upvotes: 3

b.b3rn4rd
b.b3rn4rd

Reputation: 8840

You cant use this method name in your bootstrap class '_initView' because there is corresponding Zend_Application_Resource_View, just rename your bootstrap method name

Upvotes: 2

Related Questions