我在我的模型中使用此代码,
public function registration(){
$name = 'Foo';
$city = 'Bar';
$this->User->save(
array(
'name' => $name,
'city' => $city
)
);
}
但插入时会出现致命错误
"Error: Call to a member function save() on a non-object
File: C:\xampp\htdocs\blogs\app\Model\User.php"
如何插入?
答案 0 :(得分:12)
您已经在User
模型中。只需执行以下操作:
$this->save(
array(
'name' => $name,
'city' => $city
)
);
}