2017-11-13 2 views
-2

내 컨트롤러 :방법 datatables의 CI와 함께이 매개 변수를 보낼 수

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

그리고 datatables 내 도우미 :

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없는 오류가 있지만, 매개 변수 2 일 ($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

돌아 오면이가 아직 작동하지 않습니다. 매개 변수 2nd ($ status_survey)가 포함되었지만 여전히 false를 반환하는 경우 function –

+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