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 8317007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:29:20+00:00 2026-06-08T21:29:20+00:00

I’m trying to create small application on Yii framework but can’t understand one moment.

  • 0

I’m trying to create small application on Yii framework but can’t understand one moment. I have Order model that extends from CActiveRecord and in index action I trying to use Order model twice but having some troubles.

The reason is to show paginated records in table and in last row I wish to show average totals for some fields, and this totals must be calculated for all records filtered by sort/filter criteria

Here is code of action:

public function actionIndex()
{
    $model = new Order('search');
    $model->unsetAttributes();
    if (isset($_GET['Order']))
        $model->attributes = $_GET['Order'];

    // Get average totals by current filters
    $totals = array();
    $tm = clone $model;
    $tmdp = $tm->search();
    $tmdp->criteria->select = array('avg(price) as avgPrice', 'avg(cost) as avgCost');
    $data = $tmdp->getData(true);
    $totals['cost'] = number_format($data[0]->avgCost, 0, '.', ' ');
    $totals['price'] = number_format($data[0]->avgPrice, 0, '.', ' ');
    $totals['marja'] = Order::getMarjaVal(round($data[0]->avgCost, 0), round($data[0]->avgPrice, 0));

    $this->render('index', array(
        'model'         => $model,
        'totals'        => $totals
    ));
}

In my view I’m getting data in the same way $data = $model->search()->getData();

So if I view first page – all working good, but if I change page then $data = $tmdp->getData(true); getting empty array. I also tried to set page for $tmdp like:

    $tmdp->criteria->select = array('avg(price) as avgPrice', 'avg(cost) as avgCost');
    $tmdp->pagination->setCurrentPage(0);
    $data = $tmdp->getData(true);

but after this I getting data in my view only from first page.

Please can someone tell me how to do this correctly???

  • 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-06-08T21:29:21+00:00Added an answer on June 8, 2026 at 9:29 pm

    When we change current page in pagination Yii automatically updates $_GET[‘Order_page’] value (if this value wasn’t setted – it will create it), and pagination automatically gets this value when we getting data from data provider. So for this code i made such changes:

    public function actionIndex()
    {
        $model = new Order('search');
        $model->unsetAttributes();
        if (isset($_GET['Order']))
            $model->attributes = $_GET['Order'];
    
        // Get average totals by current filters
        $totals = array();
    
        $tm = clone $model;
        $tdp = $tm->search();
        $tdp->criteria->select = array('avg(price) as avgPrice', 'avg(cost) as avgCost');
        if (isset($_GET['Order_page'])) {
            $curPage = $_GET['Order_page'] - 1;
        } else {
            $curPage = 0;
        }
        $tdp->pagination->currentPage = 0;
        $data = $tdp->getData(true);
        $totals['cost'] = number_format($data[0]->avgCost, 0, '.', ' ');
        $totals['price'] = number_format($data[0]->avgPrice, 0, '.', ' ');
        $totals['marja'] = Order::getMarjaVal(round($data[0]->avgCost, 0), round($data[0]->avgPrice, 0));
        $tdp->pagination->currentPage = $curPage;
    
        $this->render('index', array(
            'model'         => $model,
            'totals'        => $totals
        ));
    }
    

    So we trying to get page from $_GET global array and after owr operation we just update this value back

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.