Re: (Good) way of pulling data into view?

2007-06-22 Thread AD7six



On Jun 21, 4:36 pm, simon <[EMAIL PROTECTED]> wrote:

> The code in that function (get_items_this_month) just does a findAll
> based on the function parameters.

Maybe someone can write a little function to hookinto request action
that does the following

if ($calledByRequestAction&&$justAFindAll) {
 echo "JUST CALL THE DAMN MODEL!"; die;
}

:D

AD
PS. discussion is good, no hint of arrogance noted. well except maybe
in this message ;)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: (Good) way of pulling data into view?

2007-06-22 Thread dardosordi

Somethig like that, but with so litle understandig of ypur problem
cant't help you more, anyway seems like you figured out a way of doing
it.

On Jun 21, 11:36 am, simon <[EMAIL PROTECTED]> wrote:
> > In my experience, specific problems that warrant breaking rules are a
> > lot rarer than many think. Are you wanting your users to be able to
> > edit the view files? if not, your controller calls the view files - it
> > knows which view file it's going to use it should know which data it
> > wants to receive; if so, why? and in any event I'd suggest designing
> > towards the same answer ;).
>
> You're absolutely right... I think sometimes I come across as arrogant
> when I'm just trying to get a discussion going :)
>
> > If you are still not convinced, what's the code in your controller
> > method /templates/get_items_this_month/ ? specific discussions are
> > more likely to give you specific answers.
>
> The code in that function (get_items_this_month) just does a findAll
> based on the function parameters. The problem was that I needed to
> find a way of sending an array as a parameter. Like you said, I could
> actually do that with requestAction but that would not be a great
> solution.
>
> The solution I've gone for now is to split the template up. So I've
> got one THTML file (template_name.thtml) which contains some
> iterations with html inside of them. I've also got a raw include file
> (template_name.php) which gets included before rendering the template
> file.
>
> My include file basically builds a massive array with all the data I
> need and then does:
> $this->set('templateData', $templateData);
>
> dardosordi: is this maybe what you had in mind?
>
> I would have rather made the data file a component instead of an
> include, but that gave me lots of problems with things like $this no
> longer referring to the controller. Also I would have to hardcode the
> array of components to include, which means that I would have to edit
> the controller in order to add a template (I want to avoid this).
>
> Enough of my ramblings. I think I've got something working fairly well
> now, albeit not as elegant as it could be.
>
> S


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: (Good) way of pulling data into view?

2007-06-21 Thread simon

> In my experience, specific problems that warrant breaking rules are a
> lot rarer than many think. Are you wanting your users to be able to
> edit the view files? if not, your controller calls the view files - it
> knows which view file it's going to use it should know which data it
> wants to receive; if so, why? and in any event I'd suggest designing
> towards the same answer ;).

You're absolutely right... I think sometimes I come across as arrogant
when I'm just trying to get a discussion going :)

> If you are still not convinced, what's the code in your controller
> method /templates/get_items_this_month/ ? specific discussions are
> more likely to give you specific answers.

The code in that function (get_items_this_month) just does a findAll
based on the function parameters. The problem was that I needed to
find a way of sending an array as a parameter. Like you said, I could
actually do that with requestAction but that would not be a great
solution.

The solution I've gone for now is to split the template up. So I've
got one THTML file (template_name.thtml) which contains some
iterations with html inside of them. I've also got a raw include file
(template_name.php) which gets included before rendering the template
file.

My include file basically builds a massive array with all the data I
need and then does:
$this->set('templateData', $templateData);

dardosordi: is this maybe what you had in mind?

I would have rather made the data file a component instead of an
include, but that gave me lots of problems with things like $this no
longer referring to the controller. Also I would have to hardcode the
array of components to include, which means that I would have to edit
the controller in order to add a template (I want to avoid this).

Enough of my ramblings. I think I've got something working fairly well
now, albeit not as elegant as it could be.

S


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: (Good) way of pulling data into view?

2007-06-21 Thread dardosordi

Maybe you can make a template system, whre you define in a simple way
what is the data you want and make the controller fetch it from the
models and handle it to a view.

+-- (is really a special model)
  /
ReportTemplate ---> | Reports|
Models >|  Controller | > views

Could it be? Or I screwed it?

On Jun 20, 7:33 am, AD7six <[EMAIL PROTECTED]> wrote:
> On Jun 19, 1:49 pm, simon <[EMAIL PROTECTED]> wrote:
>
> > > Why isn't all of that retrieval logic in the controller? I.e. you
> > > generate all the data you want in your controller, and you simply loop
> > > on your retrieved data in the vew.
>
> > Ah, see I'm totally with you on this... I have a quite specific
> > problem though: each type of template needs a specific set of data.
>
> In my experience, specific problems that warrant breaking rules are a
> lot rarer than many think. Are you wanting your users to be able to
> edit the view files? if not, your controller calls the view files - it
> knows which view file it's going to use it should know which data it
> wants to receive; if so, why? and in any event I'd suggest designing
> towards the same answer ;).
>
> If you are still not convinced, what's the code in your controller
> method /templates/get_items_this_month/ ? specific discussions are
> more likely to give you specific answers.
>
> hth,
>
> AD


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: (Good) way of pulling data into view?

2007-06-20 Thread AD7six



On Jun 19, 1:49 pm, simon <[EMAIL PROTECTED]> wrote:
> > Why isn't all of that retrieval logic in the controller? I.e. you
> > generate all the data you want in your controller, and you simply loop
> > on your retrieved data in the vew.
>
> Ah, see I'm totally with you on this... I have a quite specific
> problem though: each type of template needs a specific set of data.

In my experience, specific problems that warrant breaking rules are a
lot rarer than many think. Are you wanting your users to be able to
edit the view files? if not, your controller calls the view files - it
knows which view file it's going to use it should know which data it
wants to receive; if so, why? and in any event I'd suggest designing
towards the same answer ;).

If you are still not convinced, what's the code in your controller
method /templates/get_items_this_month/ ? specific discussions are
more likely to give you specific answers.

hth,

AD


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: (Good) way of pulling data into view?

2007-06-19 Thread simon


> Why isn't all of that retrieval logic in the controller? I.e. you
> generate all the data you want in your controller, and you simply loop
> on your retrieved data in the vew.

Ah, see I'm totally with you on this... I have a quite specific
problem though: each type of template needs a specific set of data. So
for instance the monthly update might want all items of types A, B and
C with status confirmed and rating > 3, whereas the weekly update
might want something completely different. The controller does not
know what the template needs, and I kind of need to keep it that way.
I want to be able to add a new kind of report without having to add
specific code for that report type in the controller.

(Obviously I could for instance add a function in the reports
controller for each report type, but want to keep the controller
clean.)

> You will find that it is phenomenally slow if you requestAction all
> your data, and btw the second parameter for requestAction is an array
> - anything in it is received by the requestedAction.(but please, don't
> use requestAction to turn MVC into spaghetti).

I didn't realise that requestAction had performance implications,
thanks for pointing that out.

It does indeed go against MVC a little bit. My problem is that the
template (which is the view) needs to pull the data, which inherently
is un-MVC. Or can anyone think of a better way of structuring the
code? As I said I've considered having an include file that fetches
the data, but would like to have a single file if possible.

Thanks
S


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: (Good) way of pulling data into view?

2007-06-19 Thread AD7six



On Jun 19, 12:16 pm, simon <[EMAIL PROTECTED]> wrote:

> Or should I be going about this in some other way?

Why isn't all of that retrieval logic in the controller? I.e. you
generate all the data you want in your controller, and you simply loop
on your retrieved data in the vew.

You will find that it is phenomenally slow if you requestAction all
your data, and btw the second parameter for requestAction is an array
- anything in it is received by the requestedAction.(but please, don't
use requestAction to turn MVC into spaghetti).

cheers,

AD


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



(Good) way of pulling data into view?

2007-06-19 Thread simon

Hello,

I have a scenario where I'm not sure how to apply Cake conventions.
I'm building a reporting app where the most complex part is the report
templates (views).

My main question is: if I really, *really* want to make a function
call to a controller from a view (even though it is against the
convention), is that possible? RequestAction is proving inadequate as
I need to give more complex arguments than a string.

The main problem is that each template requires a different set of
data which is unknown to the controller, so it has to be pulled from
the view. If you have the time, continue reading, cause I could do
with some advice/opinions on what the best solution for the following
is:

-

The relevant modules for this part are the reports controller, the
template controller and the various template files. The way the flow
currently works is: the user requests to create a report to the
reports controller. A report type is specified, i.e. "/reports/create/
monthly_update"

The reports controller will then render the template  which is a THTML
file, e.g. monthly_update.thtml. Inside the template file there are
various requestActions which from the templates controller requests
the Items that are relevant. Items are tied to an Artist and have a
type and a status. So a simple template could look like:

Monthly update...
requestAction("/templates/get_items_this_month/
$artistId/".ITEMTYPE_NEWS.'/'.ITEMSTATUS_CONFIRMED);
?>
Confirmed news:


  



As a first draft this worked fine, but requestAction quickly becomes
inadequate, as each template wants to display it's specific selection
of types and statuses of items. Calling requestAction is limited as
you can't send complex stuff like arrays as arguments. So is there any
way I can make actual function calls to the template controller
instead?

Or should I be going about this in some other way? Maybe having a
separate file per template specifying what data to request before
rendering the thtml file? Would like to avoid this as I like the idea
of having a standalone template file.

Thanks, and apologies for long post...
Simon


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---