Sunday, 15 January 2012

php - How can I limit the output of a CakePHP query? -



php - How can I limit the output of a CakePHP query? -

i trying larn cakephp, , attempting replicate can standard php , mysql cake.

i have event table event information, , list_items table holds entries bullet pointed list displayed on each event page. list_items table consists of 3 columns: id,event_id,listinfo. latter string displayed.

i have associated 2 tables:

class event extends appmodel{ public $hasmany = array( 'listitem' ); }

and:

class listitem extends appmodel{ public $belongsto = array( 'event' ); }

and event controller has query find event based on id:

public function view($id = null){ if (!$id){ throw new notfoundexception(__('invalid course')); } $event = $this->event->findbyid($id); if (!$event){ throw new notfoundexception(__('invalid event')); } $this->set('event',$event); }

i have view set up:

<?php foreach($event['listitem'] $listitem): echo $this->html->nestedlist($listitem); endforeach; ?>

my problem is, outputs everything in list_items:

1 1 list item 1 2 1 list item 2

e.g. keys and actual string.

how can limit output string? bit confused way associations (heck, , mvc in general) work.

html::nestedlist() used associative arrays, not indexed.

the example cake gives shows when utilize it.

for case, this:

foreach($event['listitem'] $listitem): echo 'listitem id: ' . $listitem['id'] . ' ' . $listitem['listinfo'] . ' , belongs event:' . $listitem['event_id']; endforeach;

if debug($event); somewhere in view, see info looks , may help visualise associations better.

php mysql cakephp

No comments:

Post a Comment