【发布时间】:2010-06-18 08:51:02
【问题描述】:
hii..我想编辑单行。我用过 $this->data = $this->BuildingProperty->read(null,$id);
但它没有获取此 id 的值。
那我该怎么办。给我任何建议。
【问题讨论】:
-
这个id的记录是否存在?它是否生成正确的 SQL 查询?
标签: php cakephp cakephp-1.3
hii..我想编辑单行。我用过 $this->data = $this->BuildingProperty->read(null,$id);
但它没有获取此 id 的值。
那我该怎么办。给我任何建议。
【问题讨论】:
标签: php cakephp cakephp-1.3
为什么将null 作为第一个参数传递?它应该是您要检索的字段数组上的字符串。
不管怎样,试试这个:
$this->BuildingProperty->id = $id;
$this->data = $this->BuildingProperty->read();
【讨论】:
read() 是完全合适的。传递null 仅表示“所有字段”。 book.cakephp.org/view/1029/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));
你至少应该得到一些输出,告诉你调试调用的行。
【讨论】: