From: Chris W. <ch...@cw...> - 2004-07-17 16:17:36
|
On Jul 17, 2004, at 11:45 AM, Antti V=E4h=E4kotam=E4ki wrote: > But there is another thing I really would like to have and it would be > [system_class] configurable Request object. This would help to put=20 > thing in their correct places.. > > For example we use path to store current group id after the task name=20= > (this way we get unique paths for each groups tools) and this group id=20= > should be accessible from CTX->request->active_group . We could also=20= > solve the default task problem which arises when group id is=20 > interpreted as task name when there is no task in the url in request=20= > when at the moment we have to fix it in out custom Action class. > > There are also other things like our user securities which should be=20= > accessible through the request object. The [system_class] the wrong place for this since there's already a=20 built-in way to handle it. The request/response objects are created=20 from factories, so you just need to register your custom request object=20= with the factory. Here's how to do it: - Create a new request class. (It sounds like you've already done=20 this.) Just subclass the main one you want, like=20 OpenInteract2::Request::Apache, and override init() with something=20 like: package OpenInteract2::Request::MyCustom; use strict; use base qw( OpenInteract2::Request::Apache ); sub init { my ( $self, $params ) =3D @_; $self->SUPER::init( $params ); # ... now set your custom properties } # Register yourself with OI2::Request: OpenInteract2::Request->register_factory_type( mycustom =3D> 'OpenInteract2::Request::MyCustom' ); - Create a new/modify 'startup.pl'. This is where we tell OI2 which=20 request/response handlers to create from the factory. # Require your custom class: ... use OpenInteract2::Request::MyCustom; ... # Let OI2 know which request to create -- this is the name # we use in 'register_factory_type()' $ctx->assign_request_type( 'mycustom' ); That's it! I'll create a JIRA issue to move the factory class=20 registration into configuration for both requests/responses, then you=20 won't need to modify the startup.pl or use the registration step within=20= your custom request class Chris -- Chris Winters Creating enterprise-capable snack systems since 1988 |