Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6962377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:39:10+00:00 2026-05-27T15:39:10+00:00

I have a Yii controller action that can potentially return a very large set

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:39:10+00:00Added an answer on May 27, 2026 at 3:39 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning Yii and got into url routing problem. I have a controller as
I have the action: UPDATED Action in Item Controller. Action called from ajaxLink in
I have recently set up Yii and when I try create an app via
I'm using YII framework. I can access my site through: localhost/index.php then If I
i have a yii site that contains main layout. in this main layout file
I have created a Yii command that needs to be run every month. If
I have a Yii web service actionQuery that queries a model based on four
I have a PHP Yii application that uses an RSS feed reader. I wanted
I have a simple setup in Yii with a Model, View and a Controller
I have a basic Yii CActiveForm that I'm using to gather input from users,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.