Codeigniter:多级模型扩展不起作用。获取错误 "Class not found"
Codeigniter: Multilevel model extends not working. Getting error "Class not found"
我正在尝试在模型中应用多级扩展。
查看我下面的代码。
我有一个模型 "Order",它扩展了 CI 的核心模型
Class Order extends CI_Model {
function __construct() {
parent::__construct();
}
}
现在我正在从 "Order" 模型
创建新的 "Seller_order" 模型
Class Seller_order extends Order {
function __construct() {
parent::__construct();
}
}
现在,当我在控制器中加载 "Seller_order" 模型时。
class Seller_order_controller extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('Seller_order');
}
}
加载时出现以下错误:
Fatal error: Class 'Order' not found
请帮忙。
我需要先加载 "Order" 模型然后 "Seller_order" 吗?
我想如果我要扩展它,我不需要加载 "Order" 模型。
我不打算用很多词来概括这个,希望代码本身可以解释需要什么。
我添加了一些调试回显来帮助显示事情 运行,我在 "played" 中用它来弄清楚。
我将采用以下布局...与您的不同,因此您必须更改它以适应。
application
-> controllers
-> Seller_order_controller.php
-> models
-> Order.php
-> Seller_order.php
控制器 - Seller_order_controller
class Seller_order_controller extends CI_Controller {
function __construct() {
parent::__construct();
echo "construct(): I am the <b>Seller Order Controller</b> Constructor<br>";
$this->load->model('seller_order');
}
public function index() {
echo "This worked";
echo '<br>';
echo $this->seller_order->show_order();
}
}
型号 - Seller_order.php
require APPPATH.'models/Order.php';
Class Seller_order extends Order {
function __construct() {
parent::__construct();
echo "construct(): I am the <b>Seller Order</b> Constructor<br>";
}
}
型号 - Order.php
Class Order extends CI_Model {
function __construct() {
parent::__construct();
echo "construct(): I am the <b>Order</b> Constructor<br>";
}
public function show_order() {
echo "This is showing an Order";
echo '<br>';
}
}
附带说明: 不确定您为什么要像这样扩展模型。通常的规则是每个模块都有自己的模型。
我从来不需要这样做,但如果我曾经这样做,现在我知道怎么做了。
我正在尝试在模型中应用多级扩展。
查看我下面的代码。
我有一个模型 "Order",它扩展了 CI 的核心模型
Class Order extends CI_Model {
function __construct() {
parent::__construct();
}
}
现在我正在从 "Order" 模型
创建新的 "Seller_order" 模型Class Seller_order extends Order {
function __construct() {
parent::__construct();
}
}
现在,当我在控制器中加载 "Seller_order" 模型时。
class Seller_order_controller extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('Seller_order');
}
}
加载时出现以下错误:
Fatal error: Class 'Order' not found
请帮忙。 我需要先加载 "Order" 模型然后 "Seller_order" 吗? 我想如果我要扩展它,我不需要加载 "Order" 模型。
我不打算用很多词来概括这个,希望代码本身可以解释需要什么。
我添加了一些调试回显来帮助显示事情 运行,我在 "played" 中用它来弄清楚。
我将采用以下布局...与您的不同,因此您必须更改它以适应。
application
-> controllers
-> Seller_order_controller.php
-> models
-> Order.php
-> Seller_order.php
控制器 - Seller_order_controller
class Seller_order_controller extends CI_Controller {
function __construct() {
parent::__construct();
echo "construct(): I am the <b>Seller Order Controller</b> Constructor<br>";
$this->load->model('seller_order');
}
public function index() {
echo "This worked";
echo '<br>';
echo $this->seller_order->show_order();
}
}
型号 - Seller_order.php
require APPPATH.'models/Order.php';
Class Seller_order extends Order {
function __construct() {
parent::__construct();
echo "construct(): I am the <b>Seller Order</b> Constructor<br>";
}
}
型号 - Order.php
Class Order extends CI_Model {
function __construct() {
parent::__construct();
echo "construct(): I am the <b>Order</b> Constructor<br>";
}
public function show_order() {
echo "This is showing an Order";
echo '<br>';
}
}
附带说明: 不确定您为什么要像这样扩展模型。通常的规则是每个模块都有自己的模型。 我从来不需要这样做,但如果我曾经这样做,现在我知道怎么做了。