2017-10-03 8 views
0

がすべて必要です。ファイルがコントローラであるか、モデルで操作する必要がありますか?codeigniter: 'null'の値が0に設定されている場合コード内の

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

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); 
    } 

あなたのためのトリックが必要です。どのように動作するか教えてください。

:構文エラーがありました。今すぐ働かなければならない。

+0

これは私のように私を動作させます: \t \t $ param ['state'] = $ this-> input-> post( "state"); \t \t if(!isset($ param ['state'])){$ param ['state'] = 0; } ありがとう:D – raulmartiarena

関連する問題