CActiveDataProvider 不提供选定的列
CActiveDataProvider doesnt give selected columns
$criteria->select = 't.*,count(business_unit.id) as TotalBusinessUnits,count(users.id) as TotalUsers ,count(positions.id) as TotalPositions, count(skills.id) as TotalSkills , users.first_name , users.last_name, count(question_bank.id) as TotalQuestions';
$criteria->condition = "`t`.status = '1'";
$criteria->group = 't.id';
$criteria->order = 'created DESC';
$criteria->join = " inner join users on users.company_id = `t`.id";
$criteria->join .= " left join business_unit on business_unit.company_id = `t`.id";
$criteria->join .= " left join billingdetails on billingdetails.company_id = `t`.id";
$criteria->join .= " left join positions on positions.company_id = `t`.id";
$criteria->join .= " left join skills on skills.company_id = `t`.id";
$criteria->join .= " left join question_bank on question_bank.company_id = `t`.id";
它工作正常并得到我 select 的所有列。
但是当我在 CActiveDataProvider 中传递它时,它只获得 this
属性。
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination' => $pages
));
如何 select 所有列?
在 Yii 中,如果你使用 as
作为 sql,它需要一个 public 变量来存储值。
将所有自定义列名称添加为模型上的 public 变量,所有这些都应该是花花公子。
所以如果你有 $criteria->select = 't.*,count(business_unit.id) as TotalBusinessUnits
,这将创建相应的 sql。但 Yii 无法将 TotalBusinessUnits
识别为 table.
上的有效列
所以如果你在你的模型中添加 public $TotalBusinessUnits;
Yii 有一个地方来存储这个值。
此外,您还应该将 TotalBusinessUnits
添加到您的安全属性规则中,以便 Yii 知道可以安全获取。
public $TotalBusinessUnits;
public function rules(){
return array(
// your rules
array('TotalBusinessUnits','safe'),
);
}
public function search(){
$criteria->select = 't.*,count(business_unit.id) as TotalBusinessUnits';
// your criteria
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
$criteria->select = 't.*,count(business_unit.id) as TotalBusinessUnits,count(users.id) as TotalUsers ,count(positions.id) as TotalPositions, count(skills.id) as TotalSkills , users.first_name , users.last_name, count(question_bank.id) as TotalQuestions';
$criteria->condition = "`t`.status = '1'";
$criteria->group = 't.id';
$criteria->order = 'created DESC';
$criteria->join = " inner join users on users.company_id = `t`.id";
$criteria->join .= " left join business_unit on business_unit.company_id = `t`.id";
$criteria->join .= " left join billingdetails on billingdetails.company_id = `t`.id";
$criteria->join .= " left join positions on positions.company_id = `t`.id";
$criteria->join .= " left join skills on skills.company_id = `t`.id";
$criteria->join .= " left join question_bank on question_bank.company_id = `t`.id";
它工作正常并得到我 select 的所有列。
但是当我在 CActiveDataProvider 中传递它时,它只获得 this
属性。
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination' => $pages
));
如何 select 所有列?
在 Yii 中,如果你使用 as
作为 sql,它需要一个 public 变量来存储值。
将所有自定义列名称添加为模型上的 public 变量,所有这些都应该是花花公子。
所以如果你有 $criteria->select = 't.*,count(business_unit.id) as TotalBusinessUnits
,这将创建相应的 sql。但 Yii 无法将 TotalBusinessUnits
识别为 table.
所以如果你在你的模型中添加 public $TotalBusinessUnits;
Yii 有一个地方来存储这个值。
此外,您还应该将 TotalBusinessUnits
添加到您的安全属性规则中,以便 Yii 知道可以安全获取。
public $TotalBusinessUnits;
public function rules(){
return array(
// your rules
array('TotalBusinessUnits','safe'),
);
}
public function search(){
$criteria->select = 't.*,count(business_unit.id) as TotalBusinessUnits';
// your criteria
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}