--- Dave Howorth <Dave.Howorth at acm.org> wrote:
> Peter Speltz wrote:
> > $r->addtional_data is called before model processes request. I have
> > only ever used additional_data to add some template args. I would
> > like to use it to add object specific template args except I can't
> > because of where this method is called. ( The model class process
> > fetches the objects. ) An example is my menu. The menu data is
> > different when I'm listing Customers (working with the customer
> > class) than it is if i'm viewing a Customer (working with a specific
> > object).
> >
> > I'm wondering if people use additional_data in a way that it has an
> > effect on their model class processing . If not maybe the call to
> > $r->additional_data should happen after model processing and before
> > view processing.
>
> Hi Peter,
>
> For myself, I don't think I care where additional_data gets called but
> I'm not sure why you want to use it.
>
> If you want additional model-related data in the template, can't you
> just add it in the action ($r->template_vars->{whatever} = xxx)?
>
Well yeah. But .... I want it in EVERY action. The additional_data sub is good
for generating dynamic template args that you want for every single request.
Like a menu.
Here is the general problem:
In general the additional_data sub only allows you to generate class specific
data for your templates. This is because of where it is called. It is called
before the objects are generated. So if you go to "customer/view/21"
additional_data is called before customer 21 is even retrieved from the
database and object is created. This means you cant generate template args
based on customer 21 object in additional_data.
Here's a specific scenario:
I have a generic menu. The actions displayed on the menu depend on what
class/table you're looking at. So if you are at "customer/list" you will get a
different menu than if you are at "repair/list". Lets say the same method
generates the menu data for the template: "sub menu_data". Ok. So in
Customer.pm and Repair.pm classes I define a "menu_data" sub and thus specify
my menu. OK. Remember every page has a menu so I have to call that sub for
every page. I do not want to put "$self->menu_data;" in every single model
action. So I put it in additional_data like so: "$r->model_class->menu_data;"
Follow me? Ok. That works great when I want menus solely based on classes ie
the general customer and repair menus : "addnew, search, list". But *** I
want menus based on objects as well. ie: "edit, delete, add a repiar to John
Smith, Look at John Smiths 15 late payments, Email John Smith" . . . You see --
menu based on my objects. The difference to me is simply calling menu_data as
a class or object method. However, since I have no objects when additional_data
is called I can't call it as an object method there. If I COULD, my
additional_data would look like this:
sub additional_data {
...
# get object menu if we have only one object:
if (@{$r->objects} eq 1) {
$r=>objects->[0]->menu_data;
}
# else class menu
else {
$r->model_class->menu_data;
}
Lacking this capability, I'm left with having to put the line:
"$self->menu_data;" IN EVERY LAST ONE OF MY EXPORTED SUBS IN EVERY LAST CLASS
IN EVERY LAST MAYPOLE APPLICATION.
That's just unacceptable and i hope this gets changed unless there's good
reason to leave it as it is.
=====
pjs
__________________________________
Do you Yahoo!?
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250
_______________________________________________
maypole mailing list
maypole at lists.netthink.co.uk
http://lists.netthink.co.uk/listinfo/maypole
This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:57 GMT