hii ..我想编辑单行。我使用了 $this->data = $this->BuildingProperty->read(null,$id);
但它没有获取此 ID 的值。
那我该怎么办。给我任何建议。
hii ..我想编辑单行。我使用了 $this->data = $this->BuildingProperty->read(null,$id);
但它没有获取此 ID 的值。
那我该怎么办。给我任何建议。
你为什么null
作为第一个参数传递?它应该是您要检索的字段数组上的字符串。
无论如何,试试这个:
$this->BuildingProperty->id = $id;
$this->data = $this->BuildingProperty->read();
您使用的语法是正确的。首先检查 $id 是否为整数。(回声 $id)。如果是这样,请检查您的数据库是否在 building_properties 表中有此类记录,检查此 ID 是否存在。最后检查变量 $this->data 是否填充了正确的值。
所有这些检查都会返回正确的值,那么问题不在 Model->read() 函数中。
另一个提示,尝试清除缓存 /app/tmp/cache/modules 和 /app/tmp/cache/persistent
您是从了解 BuildingProperty 的控制器调用该方法吗?即BuildingPropertiesController
。如果没有,您是否包括了一个
var $uses = array('BuildingProperty');
类定义中的语句或显式加载模型,例如,
loadModel('BuildingProperty')
您的语法是正确的,如果没有警告或错误消息,唯一的其他解释是返回的数组为空,即记录不存在。
检查您是否已打开调试:
Configure::write('debug', 1); // or higher.A 2 will output SQL queries as well
然后尝试
debug($this->BuildingProperty->read(null,$id));
您至少应该得到一些输出,告诉您调试调用的行。