是我想要的,文件是控制器,还是应该在模型中进行操作?
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。
答案 0 :(得分:0)
通过使用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);
}
应该为你做的伎俩。让我知道它是如何工作的。
修改:出现语法错误。现在应该工作。