如果模型之间没有任何关联,你可以使用 ClassRegistry 来引用模型。
<?php
class RecipesController extends AppController {
function index() {
$recipes = $this->Recipe->find('all');
$this->Car =& ClassRegistry::init('Car');
$cars = $this->Car->find('all');
$this->set(compact('recipes', 'cars'));
}
}
?>
注意:事实上$cars = $this->Car->find('all'); 这个方法执行会报错,find 方法中应该包含fields参数。
本文介绍了一种在CakePHP框架中使用ClassRegistry进行不同模型间数据查询的方法,并提供了一个具体的示例。需要注意的是,在执行find方法时应当包含fields参数以避免错误。
1086

被折叠的 条评论
为什么被折叠?



