-- ljs629 <[email protected]> wrote
(on Tuesday, 27 October 2009, 11:37 AM -0700):
> Thanks again -
>
> I understand now what gets returned by getResource vs. getPluginResource but
> I'm a little confused as to what is considered a 'resource' and what is
> considered a 'plugin resource'?
There are three terms being used:
* bootstrap class resource (or initializer)
* bootstrap plugin resource (or initializer)
* resource
The first relates to initializers you create in your bootstrap class --
any protected method beginning with "_init":
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initDocType()
{
// ...
}
}
The second refers to those initializers that are defined in classes and
invoked by the bootstrap -- they live under the
Zend_Application_Resource_ component namespace, and provided pluggable
bootstrap resources for your application. Typically these are referenced
in configuration passed to the bootstrap, and the bootstrap then
instantiates and runs them.
Finally, the third refers to the "things" the initializers create. For
example, one might create the view object, another a database adapter.
If an initializer *returns* something, then the bootstrap stores this as
a resource. You can then retrieve that resource from the bootstrap using
the initializer's name.
> ljs629 wrote:
> >
> >
> > Ahhhh... great. And thanks for the quick response!
> >
> >
> >
> > weierophinney wrote:
> >>
> >> -- ljs629 <[email protected]> wrote
> >> (on Tuesday, 27 October 2009, 10:45 AM -0700):
> >>> I'm new to ZF and I'm trying to figure out the difference between
> >>> resource
> >>> and plugin resource - specifically, I have a working site and in the
> >>> bootstrap I init the doctype with this:
> >>>
> >>>
> >>> public function _initDocType(){
> >>> $this->bootstrap('view');
> >>> $view = $this->getResource('view');
> >>> $view->doctype('XHTML1_STRICT');
> >>> }
> >>>
> >>> And I init the registry with this:
> >>>
> >>>
> >>> public function _initRegistry()
> >>> {
> >>> $this->bootstrap('db');
> >>> $resource = $this->getPluginResource('db');
> >>> $db = $resource->getDbAdapter();
> >>> Zend_Registry::set('db', $db);
> >>> }
> >>>
> >>> My question is, why do I need to use getResource for the 'view' BUT
> >>> getPluginResource for the 'db'?
> >>
> >> You don't.
> >>
> >> getPluginResource() returns the actual plugin resource instance.
> >> getResource() will return whatever was returned by a given resource --
> >> whether it's one you've defined in your class or a plugin resource.
> >>
> >> You could change these lines:
> >>
> >> $resource = $this->getPluginResource('db');
> >> $db = $resource->getDbAdapter();
> >>
> >> to simply:
> >>
> >> $db = $this->getResource('db');
> >>
> >> since the DB resource returns the established DB adapter.
> >>
> >> --
> >> Matthew Weier O'Phinney
> >> Project Lead | [email protected]
> >> Zend Framework | http://framework.zend.com/
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/resource-vs.-pluginresource-tp26082067p26082852.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
--
Matthew Weier O'Phinney
Project Lead | [email protected]
Zend Framework | http://framework.zend.com/