I am feeling my way through CakePHP, trying to replicate what I can already do in vanilla PHP.
I have 2 tables, events
and eventlist
. events
contains general information about an event. eventlist
contains information that appears as a bullet-pointed list on each event page.
eventlist
consists of an id, an event_id which links each entry to the relevant event in the event
table, and a string that is displayed on the page. In vanilla PHP, I would simply SELECT list_info FROM eventlist WHERE event_id = 1
or whatever, and loop through the resulting array.
However, I have no idea where to start with this in CakePHP, and I'm not sure how i'd search for it to find out.
I have already created an association between the two tables:
class Event extends AppModel{
public $hasMany = array(
'EventList'
);
}
class EventList extends AppModel{
public $useTable = 'eventlist';
public $belongsTo = array(
'Event'
);
}
And I have a simple view set up for Event
:
<h2><?php echo $event['Event']['event_name'] ?></h2>
<p><?php echo $event['Event']['event_description']?></p>
<h3>£<?php echo $event['Event']['event_cost']?></p>
But now I have no idea what to do - I am new to CakePHP and MVC as a whole. I assume I need to do something in EventListController
to load the data into an array. Any help appreciated.