我正在尝试使用我的模型替换搜索(自定义搜索功能):
public function combineCampInputByDate($startDate,$endDate) {
$criteria=new CDbCriteria;
$criteria->select = 'food.*,SUM(customer) AS customer, SUM(money) AS money';
$criteria->join = 'JOIN foodType food ON foodtype = food.foodtype ';
$criteria->condition = "date BETWEEN '$startDate' AND '$endDate'";
$criteria->group = 'foodtype ';
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
结果将是模型+另一个表的属性。
我正在尝试在视图中显示它们,但它没有声明诸如 .... 之类的属性(这很清楚,因为模型没有来自另一个表的属性)
那么我如何在模型结果上使用下面的小部件?
令人沮丧,但依靠专家:) 丹尼
编辑:1.控制器 -
public function actionIndex()
{
if (isset($_POST['Filter']) && !empty($_POST['Filter']['date']) ) {
$GetDates = new GetDates();
$this->dates = $GetDates->getDatesFromPostWidget($_POST);
$model = new Campaigns;
}
else
$model=NULL;
$this->render('index',array(
'model' => $model, 'dates' => $this->dates,
));
}
模型 -
public function combineCampInputByDate($startDate,$endDate) {
$criteria=new CDbCriteria;
$criteria->select = 'food.*,SUM(customer) AS customer, SUM(money) AS money';
$criteria->join = 'JOIN foodType food ON foodtype = food.foodtype ';
$criteria->condition = "date BETWEEN '$startDate' AND '$endDate'";
$criteria->group = 'foodtype ';
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
看法
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'bo-campaigns-grid',
'dataProvider'=>$model->combineCampInputByDate($dates['startDate'],$dates['endDate']),
'filter'=>$model,
),
));
}