Strip down by attributes a large set of models

I have a Yii controller action that can potentially return a very large set of rows that are then encoded into JSON. Since the client that I am building only needs a few columns or properties of the model, I would like to strip down the set to only return certain columns. What I have now is something like:

$models = MyModel::model()->findAll($criteria);
$rows = $model->attributes;
$this->_sendResponse(200, CJSON::encode($rows));

I feel like the place to do it would be in the second line but I am new to Yii and do not know how to do this. Any help is appreciated!


maybe you could not remove unnecessary columns, but send necessary?

$models = MyModel::model()->findAll($criteria);
// do foreach loop with $models ?

$dataToSend = array()
$dataToSend['id'] = $model->id;
$dataToSend['name'] = $model->name;
$dataToSend['moreparam'] = $model->moreparam;

//send data
$this->_sendResponse(200, CJSON::encode( $dataToSend ));

So this code is more readable and we know what are we sending. If you use removing some attributes later maybe you will forget what you are leaving.

Need Your Help

How to add documentation tooltip to classes, methods, properties, etc. in C#?

c# .net visual-studio documentation

Not sure if I'm even calling this right but I wanted to start adding some documentation to my classes, methods, properties, etc. I know this is probably super obvious but I never really learned it....

How to Synchronize Red5 NetConnection Calls

java stream red5 netconnection

I am developing a online game using red5 and flex. using RTMP connection. I used only my issue is the red5 calls are not coming synchronized manor. some calls are coming to client

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.