控制器调模型方法,查不到数据【注:模型使用构造方法】

浏览:400 发布日期:2017/07/03 分类:ThinkPHP5专区 关键字: 模型 构造方法 字段不存在
Model中测试代码如下:<?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);//数据库的字段都不存在了。。
    }
}
如果模型中不使用构造方法,就可以正常使用。
结果在页面中,不存在数据的字段信息。请问这个需要如何调整呢?
最佳答案
评论( 相关
后面还有条评论,点击查看>>