[Catalyst] Catalyst::Plugin::SubRequest
Bill Moseley
moseley at hank.org
Tue Nov 29 15:57:08 CET 2005
On Tue, Nov 29, 2005 at 08:12:26AM -0600, Brandon Black wrote:
> On 11/24/05, Bill Moseley <moseley at hank.org> wrote:
> > On Thu, Nov 24, 2005 at 04:08:18PM +0000, Will Hawes wrote:
> > > I'm confused about the SubRequest plugin. In the synopsis, it says you
> > > call it like this:
> > >
> > > $c->subreq('/foo');
> > >
> > > But that currently just gives me a blank screen. The only way I've been
> > > able to get it working is
> > >
> > > $c->res->output( $c->subreq('/foo') );
> >
> > That's correct.
> >
> > I wish I had more time to help with documentation, because, at least
> > for me, some of the docs are too brief and seem to assume the reader is
> > thinking like the author.
> >
>
> I would assume that "thinking like the author" in the case of
> SubRequest is that one might serve a page which contains, for
> instance, 3 divs which can later be dynamically updated via AJAX
> calls, which are in turn also served by Catalyst. So the first time
> around, you can use $c->subreq() to grab the output of those AJAX
> calls and stuff them into your template for the whole page and serve
> it. Then later javascript code within the page might call back to
> those subreq()'d methods directly to update the individual divs,
> without any code duplication anywhere.
My comment was more that the docs show:
SYNOPSIS
use Catalyst 'SubRequest';
$c->subreq('/test/foo/bar', { template => 'magic.tt' });
Would $c->subreq ever be used in a void context?
Also, the developers thought up subrequests. If there was a reason
for that it would be helpful to see why stated in the docs. That
would be helpful for users reading the docs and understanding why
features are provided.
I don't use subreq for my Ajax calls. I use a wrapper in my
templates that conditionally builds pages. If I just want the
content without the page formatting I set something like:
$c->stash->{layout} = 'plain';
I do use $c->subreq instead of $c->forward when "redirecting" -- for
example when updating a form and redirecting back to a list.
$c->subreq allows $c->uri_for (and match/action) to be set
correctly. Helpful for generating links.
--
Bill Moseley
moseley at hank.org
More information about the Catalyst
mailing list