在codeigniter中找不到消息

时间:2016-01-27 09:16:24

标签: codeigniter

我有一个问题,我想在视图页面中发出一条消息,"没有找到数据"在codeigniter:

这是在我的控制器中:



 function search_keyword()
 {
      $this->output->set_header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
      $this->output->set_header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
      $this->output->set_header('Cache-Control: post-check=0, pre-check=0', FALSE);
      $this->output->set_header('Pragma: no-cache');
      $session_data = $this->session->userdata('logged_in');
           
      $data['Username'] = $session_data['Username'];
      $keyword    =   $this->input->post('keyword');
      $data['results']    =   $this->model_adminlogin->search($keyword);
     
      $this->load->view('result_view',$data);
 }
    




2 个答案:

答案 0 :(得分:0)

试试这个

function search_keyword()
    {
     $this->output->set_header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
     $this->output->set_header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
     $this->output->set_header('Cache-Control: post-check=0, pre-check=0', FALSE);
     $this->output->set_header('Pragma: no-cache');
       $session_data = $this->session->userdata('logged_in');
             $userName = $session_data['Username'];
             $keyword  = $this->input->post('keyword');
             $data['results']  =  $this->model_adminlogin->search($keyword);
            if(isset($data['results'])){
                $this->load->view('result_view',$data);
            }else {
              echo "<h1>Data not found </h1>"
            }

    }

答案 1 :(得分:0)

您的模型

 function search($data)
 {
      //your code
      // if found data return false otherwise true with data
       if($result->num_row()>0)
       {
           return ['status'=>true,'data'=>$result->result()];
       }
       else{
           return ['status'=>false];
       }
  }

您的控制器

 function search_keyword()
 {
      $this->output->set_header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
      $this->output->set_header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
      $this->output->set_header('Cache-Control: post-check=0, pre-check=0', FALSE);
      $this->output->set_header('Pragma: no-cache');
      $session_data = $this->session->userdata('logged_in');

      $data['Username'] = $session_data['Username'];
      $keyword    =   $this->input->post('keyword');
      $result    =   $this->model_adminlogin->search($keyword);
      if($result['status'])
      $data['results'] = $result['data'];
      else
      $data['results'] = [];

      $this->load->view('result_view',$data);
 }

在您的观看

  if(!empty($results))
  {
      //list your result
  } 
  else{
      echo 'No data Found';
  }