dongyilu3143 2019-04-14 11:29
浏览 125
已采纳

如何修复使用实体类时未找到的类? 如何在对象中显示数据库?

I was trying a tutorial from another place to show my data from an instance object. But when i try to implement it, i found error Message: Class 'Booking' not found Filename: C:\xampp\htdocs\teja\application\controllers\controlBooking.php

this is my code in class Booking

<?php namespace application\classes;
class Booking {
    protected $id;
    protected $name;
    protected $address;
public function setId(string $id){
    $this->id = $id;
}
public function getId(){
    return $this->id;
}
public function get_booking()
{
    $query = $this->db->select("*")
             ->from('booking')
             ->order_by('id', 'DESC')
             ->get();
    return $query->result();
}...

And this is my model class

<?php use application\classes\Booking;
class modelBooking extends CI_Model{
    public function get_all(){
        $book = new Booking();
        $testimoni->get_booking();
    }
}

and this is my controller

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class controlBooking extends CI_Controller {
public function __construct(){
    parent ::__construct();
    //load model
    $this->load->model('modelBooking'); 
}
public function index(){
    $data = new Booking();
    $this->load->view('viewBooking', $data);
}

then how i show it in my view class? how to fix that error? thankyou for all of you, please help me to solve this

  • 写回答

2条回答 默认 最新

  • douzhi1879 2019-04-14 15:14
    关注

    First, the file Booking.php should be moved to the folder /application/libraries/

    Then, instead of using new, use the standard CodeIgniter library loading scheme, e.g.

    $this->load->library('booking');
    

    The CodeIgniter 'Loader' (ie. $this->load->...) will locate the class file (if it is in the right place), include it, and instantiate the named class.

    Wherever you want to use the instance created by the above use

    $this->booking->some_method();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题