php - CakePHP -> 如何正确使用 findAll 和连接表?

标签 php mysql cakephp cakephp-model

我有3张 table

用户 UserHasBasicTheme(联表user.id,user_theme.id) 用户主题

我想使用 findAll 方法通过给定的 user.id 获取所有 UserTheme

每个表都有自己的模型。

我尝试使用:

$this->UserTheme->bindModel(array('hasOne' => array('UserHasBasicTheme')));
 $this->UserTheme->find('all', array(
'conditions' => array('UserHasBasicTheme.user_id' => $this->id)
 ));

但是下面的示例返回错误: 调用非对象上的成员函数bindModel()

我在用户 Controller 上调用它。

我想问一下,怎样才是正确的?

感谢您的建议。

最佳答案

您定义了 $uses 属性吗?

public $uses = array('UserTheme', 'User', 'UserHasBasicTheme');

对于 Controller ?

关于php - CakePHP -> 如何正确使用 findAll 和连接表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21166332/

相关文章:

php - Laravel + MySQL : Retrieve POI's within a bounding box

php - PDO:从数据库中获取所有未经测试的抽认卡

MySQL 显示表的数据字典

php - Laravel 迁移 : 2 different tables with the same blueprint/structure

php - 在 CakePHP 中导入 Controller 或模型更好吗?

php - 使用 PHP 制作点击计数器

PHP APC 模块。有什么缺点吗?

mysql - sql 在多位总计中引用整数

php - 获取无效状态行 10380HTTP/1.1 200 OK

php - jquery 验证插件并检查唯一字段?