Re: Where is the correct place to put this...

2006-09-28 Thread nate

Yeah, you just define it as a method in the model.  It takes the query
results as a parameter, and returns those results to the findAll
method, i.e.:

function afterFind($results) {
for ($i = 0; $i < count($results); $i++) {
// Edit the arrays here...
}
return $results;
}


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Where is the correct place to put this...

2006-09-28 Thread [EMAIL PROTECTED]

So how does afterFind() work? It sounds just like what i need to add
the comment count to the array.

There does not seem to be much documention about how you use it, im i
right in thinking i just add the function in the model and add any
ammendments to it there?


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Where is the correct place to put this...

2006-09-28 Thread Sohei Okamoto
Like other people said, if you already have data set, count($comments) would be good.If you are only interested to the count and not having the data, then I would do$num_comment = $this->Comment->findCount(array("post_id" => $post_id));
$this->set("num_comment", $num_comment);For the formatting functions, if you are formatting data to fit the database format, then I would put them in a component. If you are are formatting data for the view, I would put in a helper.
I think that is the difference and the purpose. Although, I feel that there should be one more thing that combines these two, but that's off topic.Sohei

--~--~-~--~~~---~--~~
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  -~--~~~~--~~--~--~---


Re: Where is the correct place to put this...

2006-09-28 Thread [EMAIL PROTECTED]

If you are using recursion and association you simply count the related
array to get the records.  count($data['Comment']).  I would advise
against making a requestaction call to retrieve it or putting hack code
in the view.

Another more elegant solution is to utilize the afterFind.  Just
remember that any "virtual" fields you add only work on find calls.  So
you would need to use findById() instead of read(null, $id).  or even
the setid, read.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Where is the correct place to put this...

2006-09-28 Thread Mathieu Gagnon

If the model where pass as object to the view instead of array you would 
use it right away.
For now i think you either set it in the controller or write it in the 
view, either inline if its very trivial (i think count($comments) count 
as it) or inside a custom helper.

Or if its very trivial, have a  inside the view.

I think the best way would be to use a custom helper in the view.
$custom->countComment($comments)

[EMAIL PROTECTED] wrote:
> Sorry to once again start another new thread but im having trouble
> finding where i should put functions to which i would use inside the
> view.
>
> I wish to create a countComment($post_id) function that will do... well
> what it says on the tin and return a count of the comments for the
> $post_id given.
>
> Would this function go in the model? and if so how do a reference it in
> the view?
>
> I also have a number of formatting functions i will be creating that
> will need to take data, change it then return it back.
>
> Im assume these should go in the model as well? or should i be creating
> these as components?
>
>
> >
>
>   


-- 
Mathieu Gagnon, programmation web
2649 Bourbonnière appt. 6Tel.: (514) 256-9437
Montréal (Québec) H1W 3P5Courriel.: [EMAIL PROTECTED]


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Where is the correct place to put this...

2006-09-28 Thread Chris Hartjes

On 9/28/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Sorry to once again start another new thread but im having trouble
> finding where i should put functions to which i would use inside the
> view.
>
> I wish to create a countComment($post_id) function that will do... well
> what it says on the tin and return a count of the comments for the
> $post_id given.
>
> Would this function go in the model? and if so how do a reference it in
> the view?

Having seen the light two days ago, I would advise to put the
functionality in the model.  Then, in your controller you would grab
the results of this function and then use a $this->set('foo', $bar)
type of assignment ot make it available in the view.

> I also have a number of formatting functions i will be creating that
> will need to take data, change it then return it back.
>
> Im assume these should go in the model as well? or should i be creating
> these as components?
>

If you are going to take the same data and display it multiple ways in
the view, then I think a component would be the best way to go.  I'm
sure other people will correct me if I'm wrong.


-- 
Chris Hartjes

"The greatest inefficiencies come from solving problems you will never have."
-- Rasmus Lerdorf

@TheBallpark - http://www.littlehart.net/attheballpark
@TheKeyboard - http://www.littlehart.net/atthekeyboard

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Where is the correct place to put this...

2006-09-28 Thread [EMAIL PROTECTED]

Sorry to once again start another new thread but im having trouble
finding where i should put functions to which i would use inside the
view.

I wish to create a countComment($post_id) function that will do... well
what it says on the tin and return a count of the comments for the
$post_id given.

Would this function go in the model? and if so how do a reference it in
the view?

I also have a number of formatting functions i will be creating that
will need to take data, change it then return it back.

Im assume these should go in the model as well? or should i be creating
these as components?


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---