在操作數據庫,實例化表的時候你會看大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)