[Catalyst] How to print/display some data in an end action

Mitch Jackson perimus at gmail.com
Wed Apr 30 14:46:37 BST 2008


Emmanuel,

You can store the data into the stash, and create a template for it.
Don't forget to set your content type, or whatever is receiving the
XML may not like it.  I also prefer to send a filename.

sub display : Local : Args(1) {
   ....
   my $t = $object->display_graph();
   $c->stash->{xml} = $t;
   $c->stash->{template} = 'xml.tt2';

   # Set content type
   $c->response->content_type( 'text/xml' );

   # Ask IE6, a cache offender on XML documents, to not cache this XML response
   $c->response->header( Pragma => 'no-cache' );
   $c->response->header( Expires => '-1' );

   # Set filename
   $c->response->header( 'Content-disposition', "attachment;
filename=myfile-2008-04-30.xml" );
}

.... xml.tt2
[% xml %]

If you happen to be using TTSite, you will probably have to open up
root/lib/config/col and change the closing brace at the end from %] to
-%] so it does not insert an empty line break before your content,
breaking your XML document.  ( By the standards, they can't begin with
a blank line )

/Mitchell K. Jackson

On Wed, Apr 30, 2008 at 4:51 AM, Emmanuel Quevillon <tuco at pasteur.fr> wrote:
> Hi,
>
>  I'd like to incorporate an action into an <object> tag that only prints
> some data (XML SVG).
>  I have an action in a controller Foo that do this :
>
>  sub display : Local : Args(1) {
>     ....
>     my $t = $object->display_graph();
>     $c->detach('Foo', 'end', [$t]);
>  }
>
>  sub end : Private {
>     my($self, $c) = @_;
>     my $g = $c->req->args()->[0];
>     print $g;
>  }
>
>  then in a template :
>
>  <object data="http://..../display/1"></object>
>
>  However, my output remains empty in my template.
>  If I directly call the 'display' action from my browser as :
>
>  http://.../display/1, it works ok although I get some extra code from
> Catalyst :
>
>  1HTTP/1.0 200 OK
>  Connection: close
>  Date: Wed, 30 Apr 2008 09:47:49 GMT
>  Status: 200
>  X-Catalyst: 5.7012
>
>  and so an xml error parsing reported.
>
>  So my questions are:
>
>  1: Do I do this the best way?
>  2: If so, how to avoid to print this extra code from catalyst?
>
>  Thanks in advance
>
>  --
>  -------------------------
>  Emmanuel Quevillon
>  Biological Software and Databases Group
>  Institut Pasteur
>  +33 1 44 38 95 98
>  tuco at_ pasteur dot fr
>  -------------------------
>
>  _______________________________________________
>  List: Catalyst at lists.scsys.co.uk
>  Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>  Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>  Dev site: http://dev.catalyst.perl.org/
>



More information about the Catalyst mailing list