AnN*_*LaI 5 cakephp cakephp-2.0
对不起这个基本问题.以下是我的Userscontroller.php中提供的代码
public function register()
{
//Setting some data
$this->User->create();
$this->User->save($this->request->data)
}
public function edit()
{
//Setting some data
$this->User->save($this->request->data)
}
public function admin_add()
{
//Setting some data
$this->User->create();
$this->User->save($this->request->data)
}
public function admin_edit()
{
//Setting some data
$this->User->save($this->request->data)
}
Run Code Online (Sandbox Code Playgroud)
我的一位资深人员回顾了这段代码,并说上面的代码不符合CAKEPHP标准.商业逻辑需要转移到模型
在模型中如下所示
<?php
class User extends AppModel {
//Validation parts
public functions savingData($data =array(), $id=false)
{
if($id == false)
{
$this->create();
}
$this->User->save($data)
}
}?>
Run Code Online (Sandbox Code Playgroud)
在控制器中,他要求为创建和更新选项调用此savingData函数