I’m trying to use my model with a replacement for the search (custom search function):
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,
));
}
the result will be the attributes for the model + the other table.
i’m trying to display them in the view but it states no such attribute as … (this is clear since the model doesnt have an attribiute that came from the other table)
So how do i use the widget below on the model result??
public function actionSomething()
{
$model=new YourModel('combineCampInputByDate');
…
}
[*]In model:
public $customer;
public $money;
public $startDate;
public $endDate;
…
public function rules()
{
return array(
array('…, customer, money, startDate, endDate', 'safe', 'on'=>'combineCampInputByDate'),
);
}
…
public function combineCampInputByDate() {
…
if(($this->startDate != '') && ($this->endDate != '')) {
$criteria->condition = "date BETWEEN '{$this->startDate}' AND '{$this->endDate}'";
}
…
}
Well where have you applied the changes I gave above on model, controller, and view?
Also, I should you’d better use the standard generated codes by Gii. It gives you a beautiful admin action rendering a view that includes a CGridView, and uses the model’s search method.