在CakePhp中调用unbindModel.它是如何工作的?

前端之家收集整理的这篇文章主要介绍了在CakePhp中调用unbindModel.它是如何工作的?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
unbindModel是如何在蛋糕中发生的?
$this->User->unbindModel(array('hasAndBelongsToMany' => array('Friend')));

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

我在paginate之前添加了一个unbindModel调用,它现在可以工作了.

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

unbindModel是否取消绑定每个查询?或者在整个函数调用期间解除绑定?

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@H_403_20@. If the second parameter has been set to false@H_403_20@,the bind remains in place for the remainder of the request.

换句话说,在您对paginate()或find()或对模型执行任何其他操作之后,取消绑定将被反转.

猜你在找的PHP相关文章