未找到Codeigniter 404页面未找到您请求的页面

时间:2017-11-06 06:47:18

标签: php codeigniter xampp

我搜索了很长时间,我终于找到了这个搜索和查看'谷歌的教程,但在我试图运行后,它显示我找不到404页面'。有什么错误吗?请帮帮我,谢谢你。我真的很新。

这是控制器 - >的search.php

<?php 
 function ajaxsearch()
    {

       if(is_null($this->input->get('id')))
        {

        $this->load->view('input');    


        }
        else
        {
        $this->load->model('Bookmodel'); 

        $data['booktable']=$this->Bookmodel->booktable($this->input->get('id')); 

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

        }


    }


这是模型 - &gt; Bookmodel.php

<?php 

function booktable($search){

        $query = $this
                ->db
                ->select('jantina','bangsa','agama')
                ->from('pesakit')
                ->like('rn',$search)
                ->or_like('name',$search)
                ->get();

        if($query->num_rows()>0)
        {
            return $query->result(); 
        }
        else
        {
            return null;
        }

}


这是观点 - &gt; input.php

<div class="container">

 <!-- search box container starts  -->

    <div class="search">
        <div class="space"></div>
  <form action="" method="get">

      <div class="row">
       <div class="col-lg-10 col-lg-offset-1">
        <div class="input-group">

            <span class="input-group-addon" >BOOK SEARCH</span>
  <input autocomplete="off" id="search"  type="text" class="form-control input-lg" placeholder="Search Book name or Author " >

        </div>
       </div>
      </div>   
      <div class="space"></div>
  </form>
     </div>  
  <!-- search box container ends  -->


     <div id="txtHint" style="padding-top:50px; text-align:center;" ><b>Book information will be listed here...</b></div>

</div>
<script>
  <script>
$(document).ready(function(){
   $("#search").keyup(function(){
       var str=  $("#search").val();
       if(str == "") {
               $( "#txtHint" ).html("<b>Book information will be listed here...</b>"); 
       }else {
               $.get( "<?php echo base_url();?>home/ajaxsearch?id="+str, function( data ){
                   $( "#txtHint" ).html( data );  
            });
       }
   });  
});  
</script>


这是输出视图 - &gt; output.php

<?php
    if(!empty($booktable ))  
 { 

      $output = '';
      $outputdata = '';  
      $outputtail ='';

      $output .= '<div class="container">
                   <div class="table-responsive">
                   <table class="table table-bordered">
                    <thead>
                          <tr>
                  <th>Jantina</th>
                              <th>Bangsa</th>
                              <th>Agama</th>
                  </tr>

                   </thead>
                   <tbody>
                   ';

      foreach ($booktable as $objects)    
       {   
           $outputdata .= ' 

                    <tr> 
                    <td >'.$objects->jantina.'</td>
                    <td >'.$objects->bangsa.'</td>
                    <td>'.$objects->agama.'</td>
                    </tr> 

           ';
        //  echo $outputdata; 

          }  

         $outputtail .= ' 
                         </tbody>
                         </table>
                         </div>
                         </div> ';

         echo $output; 
         echo $outputdata; 
         echo $outputtail; 
 }  

 else  
 {  
      echo 'Data Not Found';  
 }

2 个答案:

答案 0 :(得分:0)

PHP无法找到此"<?php echo base_url();?>home/ajaxsearch?id="并且您要求 Search.php控制器,除非您将搜索路径更改为 home / ,如果没有。试试这个:

替换它:

"<?php echo base_url();?>home/ajaxsearch?id="

有了这个:

"<?php echo base_url();?>search/ajaxsearch?id="

已更新答案:代表404消息

对于 Search.php控制器 替换 ajaxsearch()

用这个:

function ajaxsearch()
{   
    $id = $this->input->get('id');
    if(isset($id)){
        $this->load->model('Bookmodel'); 

        $data['booktable']=$this->Bookmodel->booktable($this->input->get('id')); 

        echo json_encode($data);
    }
    echo "error";
}

答案 1 :(得分:0)

您正在以错误的格式调用该函数。

更改您的网址

"<?php echo base_url();?>home/ajaxsearch?id="

"<?php echo base_url();?>search/ajaxsearch?id="

从此link

了解有关codeigniter网址路由的详情