Tuesday, November 27, 2012

Re: combine multiple foreach statements

I don't think it's possible to do that,... each Model has its own comments,... and there is not only Blogs and Photos, there are Groups, Videos, Dba, etc,... and I need to display them on Home page on first come first served bases,... it's kind of a Social Network site I'm rebuilding from 1.2 to 1.3,... thanks for typo notice,... lol 


On Tuesday, November 27, 2012 2:50:37 PM UTC-8, cricket wrote:
On Tue, Nov 27, 2012 at 5:20 PM, Chris <chri...@yahoo.com> wrote:
> hi cricket,...
> the codes are simple, displaying photo comments and blog comments with limit
> to 12 from controller, and they works when each one is called separately in
> home page view ... I want to combine them in ONE array on first come first
> served bases.... (some user post on Blog,... and some user post on
> Photo),...
> $i is used for how many to display in a view,... e.g. $i++ up to 12, setup
> from controller,...

So you want to mix them together? Why not merge the two arrays and
sort by created then?

If they should be mixed, but have a maximum of 12 comments, what I
would do is create a Comment model that belongs to both Photo and Blog
(each of which hasMany Comment). In the comments table include columns
model and foreign_key.

BTW, you have a typo: __('commnets', true)

And if you're running 2.x you don't need to include the second parameter.

I still don't see where you're making use of $i in this code.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: