Thanks both - that explains a lot. I did not realise that a call to
paginate was also a call to the database. Being new to Cake, I am
used to writing SQL calls 'by hand', the hardest thing seems to be
that SQL calls are 'hidden'. I know they're not really but it takes
some getting used to working out when they are being made and how you
send them the conditions etc ... all part of the learning curve I
guess.
Thanks again.
Eagle
On Aug 25, 2:08 am, "David C. Zentgraf" <[EMAIL PROTECTED]> wrote:
> Jon already pointed this out, just to make it more clear:
>
> $this->paginate() and $this->Venue->find() are both fetching data from
> the database, with the difference being that paginate() takes
> pagination into account, whereas the Model::find() method does not.
>
> $this->set() hands data over to the view.
>
> So your doing a $venues = $this->Venues->find() is great and all,
> except that you're not doing anything with the results in $venues
> after that.
> Instead you run a second query with $this->paginate('Venues'), totally
> independent of your previous $this->Venues->find(), and you're handing
> the results of this second query over to the view.
>
> If you want pagination with conditions, you will have to hand your
> conditions over to the paginate() call.
>
> On 25 Aug 2008, at 09:09, eagle wrote:
>
>
>
> > Jon,
> > Thanks for the pointer. I had looked at containable behaviour as it
> > seemed to be the solution.
> > This was what I tried (in venues_controller.php):
>
> > debug($this->Venue->find('all', array('contain' => array('Contact' =>
> > array('conditions' => array('Contact.jobType' =>'main'))));
> > $this->set('venues', $this->paginate('Venue'));
>
> > This generates the correct data (in debug view)
>
> > but if I change to:
>
> > $venues = $this->Venue->find('all', array('contain' => array('Contact'
> > => array('conditions' => array('Contact.jobType' =>'main')))));
> > $this->set('venues', $this->paginate('Venue'));
>
> > I get all the contacts displayed in the view.
>
> > So I guess my problem lies in the VIEW.....? I run a foreach loop:
> > <?php
> > foreach ($venue['Contact'] as $contact) :
> > //if ($contact['jobType'] == 'main') {
> > echo '<td>';
> > $thisContact = $contact['fName'] . ' ' . $contact['lName'];
> > echo $html->link($thisContact, 'mailto:'.$contact['email']);
> > echo ' (' . $contact['position'] . ') T: ' .$contact['telephone'] .
> > ' E: ' . $contact['email'];
> > echo "</td>";
> > //}
> > endforeach; ?>
> > and it prints ALL the contacts for that venue, but debug is telling me
> > that it has only found the correct one. At this point I got confused
> > and so moved to looking for alternative solutions.
> > Any ideas?
> > Thanks
> > Eagle
>
> > On Aug 25, 12:17 am, "Jon Bennett" <[EMAIL PROTECTED]> wrote:
> >>> I don't know how good practice it is, but in this kind of
> >>> situation, I
> >>> use to change temporarily the association conditions before
> >>> paginating, like this :
> >>> $this->Venue->hasMany['Contact']['conditions'] =
> >>> array('Contact.jobType'=>'main');
> >>> $this->paginate('Venue');
> >>> There may be more elegant solutions to do this, but ...
>
> >> yep, use the Containable
> >> behaviourhttp://book.cakephp.org/view/474/Containable
>
> >> jon
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---