2017-11-13 7 views
-2

マイコントローラ:方法のDataTableのCIとの2パラメータを送信する

function json_survey() 
{ 
    header('Content-Type: application/json'); 
    $this->load->library('Datatables'); 
    $this->load->helper('datatables_helper'); 
    $this->datatables->SELECT('id_survey,judul_survey,status_survey,responden,detail_target,judul_kategori,judul_target'); 
    $this->datatables->add_column('action',tombol_survey('$1','$2'), 'id_survey,status_survey'); 
    $this->datatables->FROM('survey'); 

    return print_r($this->datatables->generate('json','')); 
} 

そしてDataTableのための私のヘルパー:

function tombol_survey($id_survey,$status_survey) 
{ 
    $ci = & get_instance(); 
    $html = '<span class="actions">'; 
    If($status_survey=='terbit'){ 
     $html .= '<a href="' . base_url() . 'subscriber/edit/' . $id_survey . '">Tutup</a>'; 
    }elseif($status_survey=='tertunda'){ 
     $html .= '<a href="' . base_url() . 'subscriber/edit/' . $id_survey . '">Tambah</a>'; 
    }else{ 
     $html .= 'Tutup | '; 
    } 
    $html .= '<a href="' . base_url() . 'subscriber/delete/' . $id_survey . '">Lihat | </a>'; 
    $html .= '<a href="' . base_url() . 'subscriber/delete/' . $id_survey . '">Hapus</a>'; 
    $html .= '</span>'; 

    return $html; 
} 

これは、それほど含まれていないJSONないエラーが、パラメータの第二($status_survey)があります機能ifは常にfalseを返します。

答えて

0

あなたは以下のようにこれをすることによって達成することができます:

あなたのコントローラ:

function json_survey() 
    { 
     header('Content-Type: application/json'); 
     $this->load->library('Datatables'); 
     $this->load->helper('datatables_helper'); 
     $this->datatables->SELECT('id_survey,judul_survey,status_survey,responden,detail_target,judul_kategori,judul_target'); 
     $dataids = array('id_survey'=> $1,'status_survey'=> $2); //Make array and add params for survey and id and add it to the below function 
     $this->datatables->add_column('action',tombol_survey($dataids), 'id_survey,status_survey'); 
     $this->datatables->FROM('survey'); 

     return print_r($this->datatables->generate('json','')); 
    } 


function tombol_survey($ids) 
{ 
    $ci = & get_instance(); 
    if(!empty($ids)){ 
     $html = '<span class="actions">'; 
     if($ids['status_survey']=='terbit'){ 
      $html .= '<a href="' . base_url() . 'subscriber/edit/' . ($ids['id_survey']) ? ($ids['id_survey']) : ''. '">Tutup</a>'; 
     }elseif($ids['status_survey']=='tertunda'){ 
      $html .= '<a href="' . base_url() . 'subscriber/edit/' .($ids['id_survey']) ? ($ids['id_survey']) : ''. '">Tambah</a>'; 
     }else{ 
      $html .= 'Tutup | '; 
     } 
     $html .= '<a href="' . base_url() . 'subscriber/delete/' . ($ids['id_survey']) ? ($ids['id_survey']) : '' . '">Lihat | </a>'; 
     $html .= '<a href="' . base_url() . 'subscriber/delete/' . ($ids['id_survey']) ? ($ids['id_survey']) : '' . '">Hapus</a>'; 
     $html .= '</span>'; 

     return $html; 
    } 
} 
+0

を返す関数であれば、これはして、デバッグ今はパラメータ2($ status_survey)が含まれていましたが、まだfalseを返すならば関数 –

+0

@MuhammadRizki:param2が設定されていればn関数はtrueを返します。関数を一度チェックしてデバッグします。 –

+0

この機能はまだ間違っています –

0
function tombol_survey($ids) 
    { 
     $ci = & get_instance(); 
     if(!empty($ids)){ 
      $html = '<span class="actions">'; 
      if($ids['status_survey']=='terbit'){ 
       $html .= '<a href="' . base_url() . 'survey/edit/'.$ids['id_survey'].'">Tutup2</a>'; 
      }else if($ids['status_survey']=='tertunda'){ 
       $html .= '<a href="' . base_url() . 'pertanyaan/tambah/'.$ids['id_survey'].'">Tambah</a>'; 
      }else{ 
       $html .= 'Tutup | '; 
      } 
      $html .= '<a href="' . base_url() . 'pertanyaan/tambah/' .$ids['id_survey']. '">Tambah</a>'; 
      $html .= '<a href="' . base_url() . 'pertanyaan/tambah/' .($ids['status_survey']) ? ($ids['status_survey']) : ''. '">Tambah</a>'; 
      $html .= '</span>'; 

      return $html; 
     } 
    } 

私は今のparam status_surveyが含まれていますが、まだfalse

関連する問題