0

これは私のコントローラーです:

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


class Order extends CI_Controller {

public function index($id=-1) {
  $this->load->model('order');
}
}

対応する URL を開こうとすると、エラー 500 が表示されます。奇妙なことは、問題なく別のコントローラーで同じ方法でモデルをロードすることです。

念のため、ルートとモデルを次に示します。

ルート:

$route['order/(:num)'] = "order/index/$1";

モデル:

<?php
    class Order extends CI_Model {

        var $fullname = '';
        var $email = '';
        var $address = '';
        var $phone = '';
        var $notes = '';
        var $facebook = '';
        //var $canvases = '';

        var $admin_notes = '';
        var $status = '';

        var $id = '';
        var $date = '';
        var $price = '';

        //var $emailStatus_recivedOrder = '';
        //var $emailStatus_sendedOrder = '';
        //var $emailStatus_askFeedback = '';

        function __construct() {
            // Call the Model constructor
            parent::__construct();
        }

        function get($search_query='', $per_page=5, $skip=0) {

            if($search_query != '') {
                $this->db->or_where('id', $search_query);
                $this->db->or_where('email', $search_query);
                $this->db->or_where('fullname', $search_query);
                $this->db->or_where('phone', $search_query);
            }

            $query = $this->db->get('entries', $per_page, $skip);
            return $query->result();
        }

        function count_all($search_query='') {
            if($search_query != '') {
                $this->db->or_where('id', $search_query);
                $this->db->or_where('email', $search_query);
                $this->db->or_where('fullname', $search_query);
                $this->db->or_where('phone', $search_query);
            }

            $this->db->from('entries');
            return $this->db->count_all_results();
        }

        function get_by_id($id) {
            return $this->db->get_where('entries', array('id' => $id), 1);
        }

        function get_active_orders_count() {
            $this->db->where('status', '1');
            $this->db->from('entries');
            return $this->db->count_all_results();
        }

        function insert_entry() {
            $this->fullname = $this->input->post('fullname');
            $this->email = $this->input->post('email');
            $this->address = $this->input->post('address');

            $this->phone = $this->input->post('phone');

            $this->facebook = $this->input->post('facebook');

            $this->notes = $this->input->post('notes');
            $this->admin_notes = $this->input->post('admin_notes');
            $this->status = $this->input->post('status');

            $this->date   = date('Y-m-d H:i:s');

            $this->db->insert('entries', $this);
        }

        function update_entry() {
            $this->admin_notes = $this->input->post('admin_notes');

            $this->db->update('entries', $this, array('id' => $this->input->post('admin_notes')));
        }
    }

エラー: データベース エラーが発生しました

指定された設定を使用してデータベース サーバーに接続できません。

ファイル名: core/Loader.php

ライン番号: 346

4

2 に答える 2

2

コントローラーとモデルに同じ名前を付けることはできません。それらに別の名前を付ければ、問題は修正されるはずです。だから何か

コントローラ

class Order extends CI_Controller{ ... }

モデル

class Order_model extends CI_Model{ ... }
于 2013-03-20T11:03:52.213 に答える
0

In Objected oriented programming no two class can have the same name. As of codeigniter Controllers, Models are all classes. So, it is good practice to name your controller as ABC_Controller and model as ABC_Model to avoid class name conflict.

Controller

class ABC_Controller extends CI_Controller { .. }

Model

class ABC_Model extends CI_Model { .. }
于 2013-03-20T12:35:00.340 に答える