CActiveDataProvider as field

How to use as in modell in CActiveDataProvider?


$this->_criteria->select = array('id, cim, (day_'.$nowday.'_0) as start_time, (day_'.$nowday.'_1) as end_time');

If i dump this, the start_time and the end_time is null, but i search with findAll, the start_time and end_time is not null. How to set this attribute?

I’m assuming $nowday is a variable that you’re attempting to use to limit your search? If so you’re using the select property in the wrong way. The select property is only used to choose the attributes (columns) that will be assigned after a search.

Try something like this:




$criteria = new CDBCriteria;

$criteria->select = array(

    'id',

    'cim',

    'start_time',

    'end_time',

);

/*

 * Change true to false if you want a exact match

*/

$criteria->compare('start_time', 'day_' . $nowday . '_0',true);

$criteria->compare('end_time', 'day_' . $nowday . '_1',true);



In the select property you can use database functions to adjust the data before Yii gets it. I believe the main requirement (Requirement of Yii) is that the column alias must be a real column name, so you cannot just makeup an alias. e.g.




$criteria->select = array(

    'id',

    'cim',

    "DATE_FORMAT('start_time,'%m-%d-%Y') AS start_time",

    "DATE_FORMAT('end_time,'%m-%d-%Y') AS end_time",,

);