温馨提示:本文翻译自stackoverflow.com,查看原文请点击:php - 500 internal server error in codeigniter 3

php - Codeigniter 3中的500内部服务器错误

发布于 2020-03-29 21:37:18

我从Codeigniter逻辑中收到500个内部服务器错误。在控制台中看起来像这样

POST http:// localhost / apluscollege / livesearch / search 500(内部服务器错误)jquery.min.js:2

我相信该错误是由于我的.htaccess文件引起的,但我无法找到正确的错误。如果您需要更多代码,请告诉我。

<?php
  defined('BASEPATH') OR exit('No direct script access allowed');


  class Livesearch extends CI_Controller 
  {
    function __Construct() 
    {
      parent::__Construct();
      $this->load->model('Items');
    }

    public function index() 
    {
      $this->load->view('livesearch');
    }

    public function search() 
    {
      $search_data = $_POST['search_data'];
      $query = $this->Items->get_live_items($search_data);
      foreach ($query as $row):
        echo "<li><a href='#'>" . $row->title . "</a></li>";
      endforeach;
    }
  }

这是模型Items.php

<?php
  class Items extends CI_Model 
  {
    function get_live_items($search_data) 
    {            
      $this->db->select("title,description");
      $this->db->from('item');
      $this->db->group_start();
      $this->db->like('title', $search_data);
      $this->db->or_like('description', $search_data);
      $this->db->group_end();
      $this->db->limit(10);
      $this->db->order_by("id", 'desc');
      $query = $this->db->get();
      return $query->result();
    }
  }

这是livesearch.php

<form action="<?php echo base_url() . 'tiktok/search' ?>" method="post">
  <div class="input-group lrcInputs">
    <input type="text" id="search_data" class="form-control search-input" name="search-term" placeholder="What are you looking for?" onkeyup="liveSearch()" autocomplete="off">
    <div id="suggestions">
      <div id="autoSuggestionsList">
      </div>
    </div>
    <div class="input-group-btn"><button class="btn btn-success lrcSearchButton" type="submit"><i class="fa fa-search" aria-hidden="true"></i></button></div>
  </div>
</form>
</div>
<div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">
  <form action="http://vufind.carli.illinois.edu/vf-aru/Search/Home" method="get" role="search" target="vufind" name="searchForm">
    <div class="input-group lrcInputs">
      <input value="1" name="start_over" type="hidden">
      <input class="form-control" id="lookFor" name="lookfor" type="text" placeholder="Search for books, ebooks, & media">
      <div class="input-group-btn"><button class="btn btn-success lrcSearchButton" type="submit"><i class="fa fa-search" aria-hidden="true"></i></button></div>
    </div>
  </form>
  <script>
    function liveSearch() {
      var input_data = $('#search_data').val();
      if (input_data.length === 0) {
        $('#suggestions').hide();
      } else {
        $.ajax({
          method: "POST",
          url: "<?php echo base_url(); ?>livesearch/search",
          data: { search_data: input_data },
          success: function(data) {
            if (data.length > 0) {
              $('#suggestions').show();
              $('#autoSuggestionsList').addClass('auto_list');
              $('#autoSuggestionsList').html(data);
            }
          }
        });
      }
    }
  </script>

这是.htaccess文件

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

查看更多

提问者
neetu yadav
被浏览
22
Karthik Sekar 2020-01-31 18:19

打开application \ config \ autoload.php文件并添加database$autoload['libraries']数组中。

示例:$ autoload ['libraries'] = array('database');

发布
问题

分享
好友

手机
浏览

扫码手机浏览