I migrated to CakePHP3
How make result array in the CakePHP2 style, for example:
tables list:
- articles
- article_types
- producers
articles fields:
- id
- name
- article_type_id
- producer_id
in CakePHP2, find with assoc
$articles = $this->Article->find('all');
//result
$articles = [
[
'Article' => [
'id' => 1,
'name' => 'Monte',
'article_type_id' => 1,
'producer_id' => 3
],
'ArticleType' => [
'id' => 1,
'name' => 'Books'
],
'Producer' => [
'id' => 3,
'name' => 'Printhouse'
]
]
];
in cakephp3
$articles = [
'id' => 1,
'name' => 'Monte',
'article_type_id' => 1,
'producer_id' => 3,
'article_type' => [
'id' => 1,
'name' => 'Books'
],
'producer' => [
'id' => 3,
'name' => 'Printhouse'
]
];
I want put fields of main model
'id' => 1,
'name' => 'Monte',
'article_type_id' => 1,
'producer_id' => 3,
to a array:
[
'article' => [
'id' => 1,
'name' => 'Monte',
'article_type_id' => 1,
'producer_id' => 3,
],
/*other associate models*/
]
Fields in array of main model are not under modelname. Why?
For a JSON logic i need to structured data in each datum
[
'model1' => [/*fields*/],
'model2' => [/*fields*/],
'model3' => [/*fields*/],
]
How can this? manually recreate array or in the cakephp3 have a magic
option for this results?