如何在cakephp中将数据插入表中?

时间:2013-04-24 12:40:07

标签: cakephp cakephp-2.0

我在我的模型中使用此代码,

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"

如何插入?

1 个答案:

答案 0 :(得分:12)

您已经在User模型中。只需执行以下操作:

$this->save( 
    array(
        'name' => $name,
        'city' => $city
        )
    );
}