Re: [studs-devel] access to datasource from taglib
Status: Beta
Brought to you by:
mojavelinux
|
From: Dan A. <dan...@gm...> - 2005-07-10 04:45:44
|
merged
On 6/30/05, Dan Allen <dan...@gm...> wrote:
> Beautiful suggestion. Although data access in tag libraries is one of
> debate (possibly breaking MVC), I feel that a framework should not
> restrict the user from choosing to do things a certain way.
> Therefore, I will offer this method as an option, similar to Struts.
>=20
> Additionally, I would really like to see the sql tag library ported to
> Studs so that it is easy to throw together some SQL statements using
> standard tag libraries. Anyone want to give it a go?
>=20
> /dan
>=20
> On 6/30/05, Timur Vafin <ti...@e-...> wrote:
> > Hello.
> >
> > Let's assume, that it is required to create tag carrying out specific t=
hings in the project.
> > Tag should take data from from DB by interaction with a class Manager
> > which it is returned DataSource object reference.
> >
> >
> > Let's name ours tag HtmlAreaTag, which detching data by the key.
> >
> > class HtmlAreaTag extends TagSupport
> > {
> > ....
> >
> > function getBlock()
> > {
> > $manager =3D& new HtmlAreaManager(TagUtils::getD=
ataSource($this->pageContext));
> > $block =3D& $manager->getRowByAlias($this->get=
Alias());
> >
> > return is_null($block) ? '' : $block->getHtml();
> > }
> >
> > }
> >
> > For this purpose in TagUtils I suggest to add function
> >
> >
> > /**
> > * Return the default data source for the current module.
> > *
> > * @param request The HttpServletRequest we are processing
> > * @return DataSource
> > * @throws ServletException If the datasource with the specifie=
d key could not be found
> > */
> > function &getDataSource(&$pageContext, $key =3D null)
> > {
> > if (is_null($key))
> > {
> > $key =3D c('StudsConstants::DATA_SOURCE_KEY');
> > }
> >
> > // identify the current module
> > $request =3D& $pageContext->getRequest()=
;
> > $servletContext =3D& $pageContext->getServletContext();
> > $moduleConfig =3D& ModuleUtils::getModuleConfig($requ=
est, $servletContext);
> >
> > // return the requested data source instance
> > $ds =3D& $servletContext->getAttribute($key . $moduleCo=
nfig->getPrefix());
> > if ($ds =3D=3D null)
> > {
> > throw_exception(new ServletException('The datas=
ource with the requested key \'' . $key . '\' has not been configured'));
> > return;
> > }
> >
> > return $ds;
> > }
> >
> >
> >
> >
> >
> > --
> > Send plain text only to timurv at e-kazan dot ru
> > PGP key: http://wwwkeys.us.pgp.net:11371/pks/lookup?op=3Dget&search=3D=
0x425B9F0F
> > --
> > Timur Vafin
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> > from IBM. Find simple to follow Roadmaps, straightforward articles,
> > informative Webcasts and more! Get everything you need to get up to
> > speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id=16492&opclick
> > _______________________________________________
> > studs-devel mailing list
> > stu...@li...
> > https://lists.sourceforge.net/lists/listinfo/studs-devel
> >
>=20
>=20
> --
> Open Source Advocacy
> http://www.mojavelinux.com
>=20
--=20
Open Source Advocacy
http://www.mojavelinux.com
|