Friday, 27 September 2013

cakephp formatting an array

cakephp formatting an array

My goal is to display 1 Projects and many Keywords to it. My DB is simple:

Project has many Keywords
Keyword belongs to Project
So far so good. Now I try to get the Information in my ProjectsController:

public function view($id = null)
{
$this->Project->bindModel(array('hasMany' => array('Keyword' =>
array('className' => 'Keyword',
'foreignKey' =>
'project_id')
)), false);
$this->paginate['Project']['conditions'] = array('Project.id' => $id);
$this->paginate['recursive'] = '2';
$this->set('projects', $this->paginate('Project'));
$Projects = $this->paginate('Project');
$this->set('projects', $this->paginate());
}
by printing out the array it looks a bit strange:
Array
(
[0] => Array
(
[Project] => Array
(
[id] => 3
[title] => Foo
[created] => 0000-00-00 00:00:00
[modified] => 2013-08-05 17:39:07
)
[Keyword] => Array
(
[0] => Array
(
[id] => 1
[project_id] => 3
[title] => Num1
[demand] => 50000000000
[competition] => 37889.56700
[cpc] => 676.50
[created] => 2013-06-26 17:54:48
[modified] => 2013-09-19 13:37:25
)
)
[1] => Array
(
[Project] => Array
(
[id] => 4
[title] => Bar
[created] => 0000-00-00 00:00:00
[modified] =>
)
[Keyword] => Array
(
[0] => Array
(
[id] => 3
[project_id] => 4
[title] => Num1
[demand] => 76534000000
[competition] => 5555.55560
[cpc] => 99.34
[created] => 2013-06-26 17:54:48
[modified] => 2013-09-19 13:37:36
)
)
)
)
Now i have the problem, how do i display it with the right Project.id?
because the new created array contains a different id than Project.id. My
question is how do I filter the right Project.id for display it only in my
/View/[id]

No comments:

Post a Comment