使用TreeBehavior方法绑定CakePHP模型
我正在使用CakePHP树行为类使用TreeBehavior方法绑定CakePHP模型,cakephp,cakephp-2.0,cakephp-2.1,Cakephp,Cakephp 2.0,Cakephp 2.1,我正在使用CakePHP树行为类 $this->set('sports', $this->Sport->children(1,true)); 正如您在下面看到的,该函数返回我需要的子函数,但它不绑定模型。运动项目的名称存储在表标签中。关联在模型中正确定义,如果我使用“find”方法进行查询,它会绑定它们。但是有没有一种方法可以使用树行为函数和强制模型绑定呢 array( (int) 0 => array( 'Sport' => array(
$this->set('sports', $this->Sport->children(1,true));
正如您在下面看到的,该函数返回我需要的子函数,但它不绑定模型。运动项目的名称存储在表标签中。关联在模型中正确定义,如果我使用“find”方法进行查询,它会绑定它们。但是有没有一种方法可以使用树行为函数和强制模型绑定呢
array(
(int) 0 => array(
'Sport' => array(
'id' => '2',
'parent_id' => '1',
'lft' => '6',
'rght' => '7',
'tag_id' => '51f0099f-ead0-4f41-8d0f-176c9c2b3e89'
)
),
(int) 1 => array(
'Sport' => array(
'id' => '3',
'parent_id' => '1',
'lft' => '8',
'rght' => '11',
'tag_id' => '79177f20-f46a-11e2-96ba-00116b93c9e5'
)
)
)
如果您只需要直接子对象,为什么不使用Model::find方法
$this->Sport->find('all', array('conditions'=>array('Sport.parent_id'=>1))