model示例:
class Goods extends CActiveRecord
{
public static function model($className = __CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return '{{goods}}'; //'{{goods}}'会自动 添加 config中的前缀
}
function attributeLabels()
{
return array(
'goods_name'=>'商品名称',
'goods_weight'=>'重量',
'goods_price'=>'价格',
'goods_number'=>'数量',
'goods_category_id'=>'分类',
'goods_brand_id'=>'品牌',
'goods_introduce'=>'简介',
);
}
}
1.配置db
config/main.php
2.编写 model类
配置 表前缀
实例化 model
<?php
class SiteController extends Controller
{
public function actionIndex()
{
$goods = Goods::model();
var_dump($goods->findAll());
$this->render('index');
}
}
?>