1. 程式人生 > >thinkphp3.2.3 無法呼叫帶下劃線的模型

thinkphp3.2.3 無法呼叫帶下劃線的模型

thinkphp 3.2.3

如果表名中帶有下劃線,在分割的時候命名模型類,首字母大寫,例如:order_customer_bom 為表名 .模型名為OrderCustomerBomModel
引用的時候D('OrderCustomerBom') 即可呼叫.




php 控制器程式碼如下
public function getAsinLinkPrAjax()
{
$_POST['asin']=1;
$map['order_customer.asin']=$_POST['asin'];

D('OrderCustomerBom')->getAsinBomlist(123);

$u=new \Home\Model\Order_customer_bomModel();
$list=$u->getAsinBomlist();
$this->ajaxReturn($list);
}

模型程式碼如下


class OrderCustomerBomModel extends Model
{

//查詢asin下的產品清單
public function getAsinBomlist($asin)
{
$map['order_customer_bom.asin']=$asin;
$map['order_customer_bom.status']=1;
$list=M('order_customer_bom')
->field('
pid,
namezh,
nameus,
thumb,
shortname

')
->where($map)
->join('LEFT JOIN product ON order_customer_bom.pid = product.id')
->select();
}
}




真是表明如下

CREATE TABLE `order_customer_bom` (
  `id` int(11) NOT NULL,
  `asin` char(32) COLLATE utf8mb4_bin NOT NULL COMMENT 'asin',
  `type` int(8) DEFAULT NULL COMMENT '型別, 型別1 為銷售訂單.',
  `number` int(8) DEFAULT NULL COMMENT '數量',
  `pid` int(11) DEFAULT NULL COMMENT '產品id',
  `price` int(11) DEFAULT NULL COMMENT '單價',
  `status` int(3) DEFAULT NULL COMMENT '狀態 1.生效,0初始化.2刪除',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='銷售清單表';