[Catalyst] Problem with RenderView
Bogdan Lucaciu
bogdan at wiz.ro
Fri May 4 14:41:39 GMT 2007
On Friday 04 May 2007 13:34, Bernhard Graf wrote:
> For a Catalyst application I have written View classes that serialize
> DBIC ResultSets to common formats (CSV, XML) to be stored to disc.
>
> Since the amount of data can become really big, the views don't set
> $c->response->body(), but write the data directly in chunks using
> $c->write().
>
> The problem now is, that because $c->response->body() remains empty
> C:A:RenderView still thinks it has to forward to the default view.
> As a result the Catalyst error page is appended to the (CSV/XML) output
> (Couldn't render template "file error - admin/data/dump: not found").
>
> To come around this I use MyAction('RenderView') now, that
> <cite>
> return 1 if $c->response->{_finalized_headers};
> </cite>
> because finalize_headers() is called at the first call to $c->write().
>
> Any problems with this approach (besides that it access' an internal
> variable of Catalyst::Response)?
>
> Could this be included in a future release of C:A:RenderView?
First of all, why are you sending your response from the controller and not
from the view?
like this:
package Foo::View::Moo;
sub process {
# build csv/xml/etc
# set headers
# c->write it
}
package Foo::Controller::Bar;
sub moo : Local {
...
$c->stash->{data} = $data;
$c->stash->{current_view} = 'Moo';
}
RenderView doesn't use a default view, it uses $c->view();
You can read about it here:
http://search.cpan.org/perldoc?Catalyst#%24c-%3Eview(%24name)
--
Bogdan Lucaciu
http://www.wiz.ro
More information about the Catalyst
mailing list