php - CakePhp 中的 unbindModel 调用。它是如何工作的?

标签 php cakephp

cake中unbindModel是怎么发生的?

$this->User->unbindModel(array('hasAndBelongsToMany' => array('Friend')));

我在一个函数的开头写了这个。但它仍然查询“ friend ”模型。在函数中间调用了 paginate() 。所以我认为分页器可能会生成查询。

我确实在分​​页之前添加了一个 unbindModel 调用,它现在可以工作了。

$this->User->unbindModel(array('hasAndBelongsToMany' => array('Friend')));
$user = $this->paginate("User", array("User.first_name LIKE" => $user["User"]["first_name"]));

unbindModel 是否取消绑定(bind)每个查询?还是在整个函数调用期间解除绑定(bind)?

最佳答案

From the manual :

Removing or adding associations using bind- and unbindModel() only works for the next model operation unless the second parameter has been set to false. If the second parameter has been set to false, the bind remains in place for the remainder of the request.

换句话说,在您 paginate()find() 或对模型执行任何其他操作后,解除绑定(bind)将被逆转。

关于php - CakePhp 中的 unbindModel 调用。它是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1587224/

相关文章:

php - Sql 查询存储在变量中并使用该变量使用 PHP 添加内容

php sql 数据/表适用于较小的示例 txt 文件,但不适用于完整的 50mb txt 文件?

php - 内容和标题不会显示在 Wordpress 的某些页面上

php - 执行此代码的更好方法

sql - 我怎样才能在cake php中进行sql联合?

PHP:测试三个变量是否相等

php - Zend + 表关系上的 Doctrine 错误

php - 如何在数据库架构中表达购物网站的工作流和数据结构及其操作?

php - 如何使用 CakePHP 的新 Blowfish/Bcrypt 获取密码

cakephp - 如何在cakephp中获取最后一个ID