[fw-core] Getting the bootstrap from within models, etc. during the bootstrap phase

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[fw-core] Getting the bootstrap from within models, etc. during the bootstrap phase

Douglas Needham
Greetings everyone,

I wanted to start a discussion here regarding a problem I encountered
with an application I am writing.  The version of the framework was
originally 1.11.4, but the ZF RPM repository (from which we installed
our Zend Server environment) was finally up to 1.11.10 and I updated the
system.

My problem was that during the bootstrap of an admin module, I wanted to
make a call to a resource (in this case, a model) which has been working
fine up until now.  However, I found that my DbTable could not retrieve
the multidb plugin.  The code I was using in the DbTable was as follows:

            /**
             * Initialize database adapter.
             *
             * @return void
             */
            protected function _setupDatabaseAdapter()
            {
                $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
                $multidb = $bootstrap->getPluginResource('multidb');
                $dbAdapter = $multidb->getDb('admin');
                parent::_setAdapter($dbAdapter);
            }

Please note that this follows the standard pattern shown on various
articles on the web of getting the FC instance, and calling getParam()
to get the bootstrap.  In addition, this model was going to be
serializing the ACLs it retrieved, and would be relying on a value from
a configuration file, which would again need the bootstrap to call
getOptions(), and this problem would crop up there again.  The problem
is that the bootstrap has not been stored into the parameters of the FC,
and only the displayExceptions is set.

Now, there are tricks I can do to work around this, such as using
Zend_Registry and register the options, multidb, etc.  But it seems to
me that the true fix would be to have the bootstrap set when the FC is
created, instead of waiting until after the bootstrap has completed, and
we get to Zend_Application_Bootstrap_Bootstrap::run() at line 96.

Thoughts?  Do we have a bug that I should enter into JIRA??  If not, why
do we not set the bootstrap as soon as we have the FC instantiated?

- Doug

--
Douglas Wade Needham - KA8ZRT        UN*X Consultant & UW/BSD kernel programmer
Email:  cinnion @ ka8zrt . com       http://www.ka8zrt.com
Disclaimer: My opinions are my own.  Since I don't want them, why
            should my employer, or anybody else for that matter!



--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: [fw-core] Getting the bootstrap from within models, etc. during the bootstrap phase

Konr Ness
I may be misunderstanding the problem, but it seems to me this is a
problem of resource bootstrapping order and dependencies between
resources. In this case, the multidb resource has a dependency on the
frontController resource. If that's the case, maybe the problem is the
order of the items in your application.ini. Try putting
resources.multidb after resources.frontController.

If that's not the issue, what is the error that you are receiving? Why
could your code not retrieve the multidb resource?

I also prefer to explicitly bootstrap my resources before attempting
to retrieve them from the application bootstrap, like so:

           /**
            * Initialize database adapter.
            *
            * @return void
            */
           protected function _setupDatabaseAdapter()
           {
               $bootstrap =
Zend_Controller_Front::getInstance()->getParam('bootstrap');
               $multidb =
$bootstrap->bootstrap('multidb')->getResource('multidb');
               $dbAdapter = $multidb->getDb('admin');
               parent::_setAdapter($dbAdapter);
           }

This may make a difference.

Konr

On Tue, Oct 4, 2011 at 1:55 PM, Douglas Needham <[hidden email]> wrote:

> Greetings everyone,
>
> I wanted to start a discussion here regarding a problem I encountered
> with an application I am writing.  The version of the framework was
> originally 1.11.4, but the ZF RPM repository (from which we installed
> our Zend Server environment) was finally up to 1.11.10 and I updated the
> system.
>
> My problem was that during the bootstrap of an admin module, I wanted to
> make a call to a resource (in this case, a model) which has been working
> fine up until now.  However, I found that my DbTable could not retrieve
> the multidb plugin.  The code I was using in the DbTable was as follows:
>
>            /**
>             * Initialize database adapter.
>             *
>             * @return void
>             */
>            protected function _setupDatabaseAdapter()
>            {
>                $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
>                $multidb = $bootstrap->getPluginResource('multidb');
>                $dbAdapter = $multidb->getDb('admin');
>                parent::_setAdapter($dbAdapter);
>            }
>
> Please note that this follows the standard pattern shown on various
> articles on the web of getting the FC instance, and calling getParam()
> to get the bootstrap.  In addition, this model was going to be
> serializing the ACLs it retrieved, and would be relying on a value from
> a configuration file, which would again need the bootstrap to call
> getOptions(), and this problem would crop up there again.  The problem
> is that the bootstrap has not been stored into the parameters of the FC,
> and only the displayExceptions is set.
>
> Now, there are tricks I can do to work around this, such as using
> Zend_Registry and register the options, multidb, etc.  But it seems to
> me that the true fix would be to have the bootstrap set when the FC is
> created, instead of waiting until after the bootstrap has completed, and
> we get to Zend_Application_Bootstrap_Bootstrap::run() at line 96.
>
> Thoughts?  Do we have a bug that I should enter into JIRA??  If not, why
> do we not set the bootstrap as soon as we have the FC instantiated?
>
> - Doug
>
> --
> Douglas Wade Needham - KA8ZRT        UN*X Consultant & UW/BSD kernel programmer
> Email:  cinnion @ ka8zrt . com       http://www.ka8zrt.com
> Disclaimer: My opinions are my own.  Since I don't want them, why
>            should my employer, or anybody else for that matter!
>
>
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: [fw-core] Getting the bootstrap from within models, etc. during the bootstrap phase

Douglas Needham
No... the problem is that there is no access to the bootstrap object
from the front controller, while we are bootstrapping modules.  And
because of that, no access to the multidb, log, options, etc. loaded by
application/Bootstrap.php, or already loaded by by other modules or the
current module.  The bootstrap does not become available via the front
controller parameters until after we have returned to index.php and
started "running" the application.

Net result... any plugins, models, etc. which need to be called during
the bootstrap process must use a totally different process in order to
get options or other resources, rather than getting the front controller
instance, and getting the bootstrap from the parameters.

- Doug

--
Douglas Wade Needham - KA8ZRT        UN*X Consultant & UW/BSD kernel programmer
Email:  cinnion @ ka8zrt . com       http://www.ka8zrt.com
Disclaimer: My opinions are my own.  Since I don't want them, why
            should my employer, or anybody else for that matter!


--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]