Where Do These Columns Come From When Object To Json?

Hi,

I’m using this code to get only 3 columns of my Blogs:




		$criteria = new CDbCriteria();			

		$criteria->select = 'id,title,date';

		$criteria->limit = 10;		

		$blogs = Blog::model()->findAll($criteria);

		print_r($blogs);




Works great, the print_r gives me:





Array

(

[0] => Blog Object

(

[_new:CActiveRecord:private] =>

[_attributes:CActiveRecord:private] => Array

(

[id] => 1

[title] => Blog title

[date] => 02-03-2014 01:20:12

)

[_related:CActiveRecord:private] => Array

(

)

[_c:CActiveRecord:private] =>

[_pk:CActiveRecord:private] => 5

[_alias:CActiveRecord:private] => t

[_errors:CModel:private] => Array

(

)

[_validators:CModel:private] =>

[_scenario:CModel:private] => update

[_e:CComponent:private] =>

[_m:CComponent:private] =>

)

) 



But when I want to use this with Javascript and I do this in my view:




var blogs = ".CJSON::encode(CHtml::listData($blogs, 'id', 'attributes')).";



It results in:




var blogs = {"1":{"id":"1","title":"Blog title","date":"02-03-2014 01:20:12","category_id":null,"user_id":null,"content":null,"active":null,"checks":null,"copies":null,"hits":null,"likes":null}};



Yes, the ‘not selected’ column values are NULL, but the columns are printed.

Where do these columns come from I didn’t select in the first place? I don’t want people to see these columns in my html code. For this blog it’s not a big deal, but some tables got columns I don’t want to show up in the html code.

I’m confused? :blink:

Ok, I found the why: http://www.yiiframework.com/forum/index.php/topic/1768-cjson-output-should-not-include-columns-not-queried/

But still looking for a way to fix this…