Thinkphp 数据模型大M()方法和大D()方法

在操作数据库,实例化表的时候你会看大M()方法和大D()方法,他们都可以实例化表,但是也有不同的地方,下面详细讲述内容

1,M()方法  D()方法

<?php
namespace Home\Controller;
use Think\Model;

/**
 *  类继承公共类
 *  功能 :主页跟子页面分类数据
*/

class IndexController extends CommController {
    public function index(){
          //网店配置
          $this->assign('siteconfig',$GLOBALS['siteconfig']);
          //显示友情链接
          $this->assign('alllinks',$GLOBALS['alllinks']);  
          $Model=D('Goods');
          $type = D('type');
          $res=$type->where("pid=0")->select();
          foreach ($res as $k => $v) {
             $yi=$type->where("pid=".$v['id'])->limit(3)->select();
             $res[$k]['cc']=$yi;
          }
          //品牌
          $pp   = M('Brand'); //品牌表
          $ppg  = $pp->where("typeid=1")->select(); //1.的品牌

         $this->display();
    }

2,数据模型建立

文章来自(www.dc3688.com)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章