I'll try my best to explain what it is.
I have two tables 'regularplanets' and 'moons'. Idea is, regularplanets can have many moons and moons can have 1 planet. I have included the required variables 'hasMany' and 'belongsTo' in regularplanets and moons model.
What I want to do is this (shot of my webpage):
http://cl.ly/281O2V1g0x3L103T1s2B
Here, Name of the planet is 'abc' and in one of the links I have 'Show Moons'. So, when a user clicks 'Show Moons' I want it to go to another page and that lists every single moon that the planet 'abc' has.
My moons table looks like this:
http://cl.ly/1n2L190l3Z0C2k1C063L
In here, regularplanet_id references the id of the planet from the 'regularplanets' table. For example:
abc has id 1 and in the moons table:
http://cl.ly/47100k1c2l3W3B232p2u
I tried writing this code in the moons_controller for displaying the moons a regularplanet has (This is where I have my problem):
function shownumber ($id = null) {
// $this->Moon->Regularplanet ->id = $id;
//pr ($this->Moon->Regularplanet->id);
$this->set ('moons', $this->Moon->find('all'));
$this->Moon->regularplanet_id = $id;
$this -> set ('lists', $this->Moon->regularplanet_id);
$this->set ('regularplanets', $this->Regularplanet->find('all'));
}
When I try to print using the pr command in shownumber.ctp. This is what I get:
http://cl.ly/0e2i3l2K3t3Z2S2t2I2f
I just can't figure out how to display the number of moons of each planet. How do I make a loop to run through the above displayed array in which it looks for regularplanet_id = 1 (for regularplanet: 'abc') and display the moons corresponding to it.
Please any help?
I'm almost towards the end of my project.