php - Custommize get column from findAll function Yii -
i have problem that, using criteria customize number column query
$criteria=new cdbcriteria(); $criteria->select =array('companyname', 'companycountcoupon','companydes', 'companylogo'); $models = company::model()->findall($criteria);
after put array , echo result
$rows = array(); foreach($models $i=>$model1) { $rows[$i] = $model1->attributes; } echo cjson::encode($rows)
my problem results contains attributes of table, , attributes not in criteria->select set = null
{"companyname":"abc","companycountcoupon":"0","companydes":"hello","companylogo":"\/upload\/company\/abc.jpg",**"companyid":null,"companywebsite":null,"companyadrress1":null,"companyadrress2":null,"companyphone1":null,"companyphone2":null**}
please me. all
if go findall()
(using activerecord) won't able control part, way go custom query :
$results = yii::app()->db->createcommand() ->select('companyname ,companycountcoupon ,companydes ,companylogo') ->from('company') //->where() // part ->queryall(); echo cjson::encode($results);
now json encoded , faster regular activerecord
Comments
Post a Comment