在我想要的全部,文件是控制器,或者我应该在模型中进行操作?
public function newUser(){
$param['name'] = $this->input->post("name");
$param['email'] = $this->input->post("email");
$param['user'] = $this->input->post("user");
$param['password'] = sha1($this->input->post("password"));
$param['state'] = $this->input->post("state"); //<-- this value is a checkbox, if is unckecked the value became 'null'. What I want is to change that 'null' value to 0 before to send to the database.
$this->mdatabase->newUser($param);
}
谢谢:d。
通过使用 isset
,我们可以检查变量是否设置为任何值,或者为null。然后,我们可以应用逻辑来相应地分配您的值。
public function newUser(){
$param['name'] = $this->input->post("name");
$param['email'] = $this->input->post("email");
$param['user'] = $this->input->post("user");
$param['password'] = sha1($this->input->post("password"));
if(!isset($param['state'])
$param['state'] = 0;
else if(isset($param['state'])
$param['state'] = $this->input->post("state");
$this->mdatabase->newUser($param);
}
应该为您努力。让我知道它的工作原理。
编辑:有一个语法错误。现在应该工作。