2017-12-17 8 views
0

보기 CodeIgniter의 뷰 파일에 변수를 찾을 수 없습니다 :

<table class="table table-hover"> 
        <tr> 

        <th>Heading</th> 
        <th>Description</th> 
        </tr> 
        <?php foreach ($result as $row) { ?> 
        <tr> 


        <td><?php echo $row->heading_name ;?></td> 
        <td><?php echo $row->description_name; ?></td> 

        </tr> 
        <?php } ?> 
</table> 

모델 :

function view_description(){ 
     $this->db->order_by("id","DESC"); 
     $query = $this->db->get("description_update"); 
     return $query->result(); 
    } 

컨트롤러 :

public function update_heading(){ 
     $config = array(
      array(
       'field' =>'heading_name', 
       'label' =>'Name', 
       'rules' => 'trim|required' 
      ), 
      array(
       'field' => 'description_name', 
       'label' => 'Description', 
       'rules' => 'trim|required' 
      ) 
     ); 

     $this->form_validation->set_rules($config); 
     if ($this->form_validation->run()== FALSE) 
     { 
      $this->load->view('modules/admin/general.php'); 
     } 
     else{ 
      $data = array(
      'heading_name' => $this->input->post('heading_name'), 
      'description_name' => $this->input->post('description_name') 
      ); 

      $this->description_model->add_description($data); 

      $data['message'] = 'Data inserted Successfully'; 
      $this->load->view('modules/admin/general.php',$data); 
     } 
     $data['result']= $this->description_model->view_description(); 
     $this->load->view('modules/admin/general.php',$data); 
     // print_r($data); 


    } 

내보기 파일에 결과 데이터를 보려는하지만, 그것은 결과 변수를 찾지 못했지만 $ 결과 데이터가 다른 뷰 파일에 결과를 보여줄 때 같은 코드에서 나타납니다. 무엇을해야할지 모르겠습니다. 참고 : 나는 CodeIgniter의

TIA

답변

0

당신의 목표는 결과 데이터를로드하는 것입니다으로 29 줄이보기를로드 할 필요를 새로운 오전 없습니다.

$ this-> load-> view ('modules/admin/general.php', $ data);

+0

메시지가 제거되었지만 동일한 문제 메시지 : 정의되지 않은 변수 : 결과 – Arman

0

추천하고 양식의 잘못된 부분에 코드의 상단에 $data['result']을 배치 봅니다 뷰를로드 할 때 필요하지 않은뿐만 아니라 $data 또한

를 추가 .php

$this->load->view('modules/admin/general', $data);

기능

public function update_heading(){ 

    $config = array(
     array(
      'field' =>'heading_name', 
      'label' =>'Name', 
      'rules' => 'trim|required' 
     ), 
     array(
      'field' => 'description_name', 
      'label' => 'Description', 
      'rules' => 'trim|required' 
      ) 
    ); 


    $this->form_validation->set_rules($config); 

    $data['message'] = ''; 

    // $data['result'] = array(); 

    $data['result'] = $this->description_model->view_description(); 

    if ($this->form_validation->run()== FALSE) { 

     $this->load->view('modules/admin/general', $data); 

    } else { 

     $data = array(
      'heading_name' => $this->input->post('heading_name'), 
      'description_name' => $this->input->post('description_name') 
     ); 

     $this->description_model->add_description($data); 

     $data['message'] = 'Data inserted Successfully'; 

     $this->load->view('modules/admin/general',$data); 
    } 
} 
+0

이 오류 메시지는 계속 표시됩니다. 메시지 : 정의되지 않은 변수 : 결과 – Arman