我正在使用tableRegistry :: get()并返回查询对象。我只想要在CakePHP2.X版本中通过find()函数返回的表的数据。为此我需要使用" hydrate"正如我在其中一个建议中所读到的那样。这是我的代码:
public function beforeFilter(Event $event){
$this->maincategories();
}
function maincategories(){
$postcategories = TableRegistry::get('Postcategories',[
'className' => 'App\Model\Table\PostcategoriesTable',
'table' => 'postcategories'
]);
$query = $postcategories->find('all',['fields'=>[
'Postcategory.id',
'Postcategory.name'
], 'contain' => ['']])->hydrate(false)->toArray();
pr($query);exit;
}
此代码仍然给我错误" Postcategories与"
无关答案 0 :(得分:0)
删除空包含
$query = $postcategories->find('all')
->select(['Postcategory.id', 'Postcategory.name'])
->hydrate(false)
->toArray();
答案 1 :(得分:0)
我使用“线程”查找查询
排列
(
[0] =>排列
(
[id] => 1
[parent_id] =>
[name] => Web开发
[有效] => 1
[lft] => 1
[rght] => 6
[created] => Cake \ I18n \ Time Object
(
[date] => 2015-02-10 14:11:19.000000
[timezone_type] => 3
[timezone] =>世界标准时间
)
[modified] => Cake\I18n\Time Object
(
[date] => 2015-02-10 14:11:19.000000
[timezone_type] => 3
[timezone] => UTC
)
[children] => Array
(
[0] => Array
(
[id] => 2
[parent_id] => 1
[name] => Open Source
[active] => 1
[lft] => 2
[rght] => 5
[created] => Cake\I18n\Time Object
(
[date] => 2015-02-10 14:11:54.000000
[timezone_type] => 3
[timezone] => UTC
)
[modified] => Cake\I18n\Time Object
(
[date] => 2015-02-10 14:11:54.000000
[timezone_type] => 3
[timezone] => UTC
)
[children] => Array
(
[0] => Array
(
[id] => 3
[parent_id] => 2
[name] => PHP
[active] => 1
[lft] => 3
[rght] => 4
[created] => Cake\I18n\Time Object
(
[date] => 2015-02-10 15:57:11.000000
[timezone_type] => 3
[timezone] => UTC
)
[modified] => Cake\I18n\Time Object
(
[date] => 2015-02-10 15:57:11.000000
[timezone_type] => 3
[timezone] => UTC
)
[children] => Array
(
)
)
)
)
)
)
[1] => Array
(
[id] => 4
[parent_id] =>
[name] => Technology
[active] => 1
[lft] => 7
[rght] => 8
[created] => Cake\I18n\Time Object
(
[date] => 2015-02-11 11:26:22.000000
[timezone_type] => 3
[timezone] => UTC
)
[modified] => Cake\I18n\Time Object
(
[date] => 2015-02-11 11:26:22.000000
[timezone_type] => 3
[timezone] => UTC
)
[children] => Array
(
)
)
[2] => Array
(
[id] => 5
[parent_id] =>
[name] => Frameworks
[active] => 1
[lft] => 9
[rght] => 10
[created] => Cake\I18n\Time Object
(
[date] => 2015-06-19 16:24:24.000000
[timezone_type] => 3
[timezone] => UTC
)
[modified] => Cake\I18n\Time Object
(
[date] => 2015-06-19 16:24:24.000000
[timezone_type] => 3
[timezone] => UTC
)
[children] => Array
(
)
)
)