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

Vin*_* VT 1 cakephp cakephp-2.0

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

public function registration(){
$name = 'Foo';
$city = 'Bar';

$this->User->save( 
    array(
        'name' => $name,
        'city' => $city
        )
    );
}   
Run Code Online (Sandbox Code Playgroud)

但插入时会出现致命错误

"Error: Call to a member function save() on a non-object
 File: C:\xampp\htdocs\blogs\app\Model\User.php"
Run Code Online (Sandbox Code Playgroud)

如何插入?

Bar*_*man 12

你已经在User模特中了.只需执行以下操作:

$this->save( 
    array(
        'name' => $name,
        'city' => $city
        )
    );
}   
Run Code Online (Sandbox Code Playgroud)