[Catalyst] Access Catalyst context object from script

Anthony Gladdish anthony.gladdish at newcastle.ac.uk
Wed Oct 31 12:30:35 GMT 2012


>-----Original Message-----
>From: Ian Docherty [mailto:catalyst at iandocherty.com]
>Sent: 31 October 2012 11:29
>To: The elegant MVC web framework
>Subject: Re: [Catalyst] Access Catalyst context object from script
>
>On 31 October 2012 10:41, Anthony Gladdish
><anthony.gladdish at newcastle.ac.uk> wrote:
>> Hi,
>>
>> Got a lot of code in a controller that should be moved out and
>into an external script (that's called by a cronjob) which calls
>stuff from the Model and then emails it.
>>
>> The script can access the model fine and re-use a
>Template::Toolkit template already written fine (I'm using
>MIME::Lite::TT). However, in the template itself there's a lot of
>calls to the Catalyst context object, in the form of:
>>
>>         [% Catalyst.uri_for( ... ) %]
>>
>> ... which aren't displaying anything. I don't really want to hard
>code the URIs, so is there a way to get access to the Catalyst
>context object of a running app, in a separate external script?
>>
>I can understand the reluctance to hard-code URIs, however i
>would be
>reluctant to suggest that you bring in the whole of Catalyst just
>to
>satisfy this one requirement.
>
>What is the template? I presume it is an email, and that you are
>putting links to locations within your Catalyst application into the
>email?

Correct. It's a bog standard .tt file printing text to be sent as an email,
containing links to actions within the Cat app. 

>What form of uri_for are you using? If it is just to capture the
>applications root then could you replace it with your own
>convenience
>routine that just implemented that aspect of what uri_for is
>doing
>without bringing in the whole of Catalyst?
 
[% Catalyst.uri_for(Catalyst.controller('MyController').action_for('myaction'), [ some_id ] ) %]

Could you offer an example, based on my uri_for example above?

Thanks,
Anthony



More information about the Catalyst mailing list