<?php
namespace app\common\model;
use think\Model;
class Order extends Model
{
protected $orderInfo;
//开启构造方法导致无法查询
public function __construct()
{
parent::__construct();
if ($this->orderInfo == null) $this->orderInfo = new OrderInfo();
}
}
然后在控制器中,使用模型就会查询不到数据<?php
namespace app\index\controller;
use app\common\model\Order;
class OrderController extends CommonController
{
//模型
protected $order = null;
public function __construct()
{
parent::__construct();
if ($this->order == null) $this->order = new Order();
}
/**
* 查询数据
*/
public function index()
{
//使用模型查询数据
$list = $this->order->select();
dump($list);//数据库的字段都不存在了。。
}
}
如果模型中不使用构造方法,就可以正常使用。结果在页面中,不存在数据的字段信息。请问这个需要如何调整呢?
最佳答案
