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

  • SEARCH
  • Home
  • 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 8679283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:55:59+00:00 2026-06-12T20:55:59+00:00

I’ve a custom data provider in my Model I tryied this in controller public

  • 0

I’ve a custom data provider in my Model

I tryied this in controller

public function actionMonthTotal()
{
    $model=new Rapporti();
    $this->render('monthTotal',array(
            'dataProvider'=>$model->monthTotal(),
    ));
}

Where monthTotal is the model function that give me a DataProvider

Actually ‘monthTotal’ is a copy/past of view.php and it uses a clistView using _monthTotal, that is a copy/past of _view.php

I Need to simply get the dataset from dataProvider (a ‘SELECT COUNT, SUM, SUM, etc…”) and iterate into recordset to echo a simple TABLE into monthTotal view . So …

how to use a dataProvider from a view to get records and how to iterate trough recors?

My month total is this and is in ‘Report’ Model

Actually report is in a relation Report N -> 1 Pionierato (sorry for italian terms, but are only object names)

public function totalMonth() {
    $criteria = new CDbCriteria();
    $criteria->with = array ('pionierato');
    $criteria->condition = 'dataBetel=:month';
    $criteria->select = "COUNT(t.id) as numProclamatori,
                            pionierato.tipo as tipoPionierato,
                            SUM(libri) as sommaLibri,
                            SUM(opuscoli) as sommaOpuscoli,
                            SUM(ore) as sommaOre,
                            SUM(riviste) as sommaRiviste,
                            SUM(visite) as sommaVisite,
                            SUM(studi) as sommaStudi";

    $criteria->group  = "t.dataBetel, t.pionieratoId";
    $criteria->params = array ('month' => "2012-09-01");

    $dataProvider=new CActiveDataProvider('Rapporti', 
                                           array ('criteria' => $criteria)
                                         );

    return $dataProvider;
}

I need to use this dataprovider to get the 3 record it will output and print a 3-row table. Static.

Using suggestion from first answer, i got this:

Actual results

  • 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-12T20:56:00+00:00Added an answer on June 12, 2026 at 8:56 pm

    Try:

    public function actionMonthTotal()
    {
        $model = Rapporti::model()->monthTotal();
        $this->render('monthTotal',array(
                'dataProvider'=>$model,
        ));
    }
    

    That should work, you are creating an object with the name $model which has a value equal to the return value of the method monthTotal() in the Rapporti model

    If that doesn’t work, check that you are actually getting a result from your monthTotal function by copying it (minus the return part) into your controller instead of calling it from the model.

    In your monthTotal view you can iterate through the active records using CListView like so:

    <?php $this->widget('zii.widgets.CListView', array(
        'dataProvider'=>$dataProvider,
        'itemView'=>'_view',
    )); ?>
    

    Each iteration calls in a subview called “_view”. The data for that record can be accessed using $data (eg: $data->id);

    Here is an example of querying without using CActiveDataprovider:

    $model = Rapporti::model()->findAll(array(
        'condition' => 'dataBetel=:month',
        ...
    ));
    

    You can try that… Alternatively you can use findAllBySql() instead of findAll() and type in your query that way. You will then be able to iterate through your data set using a foreach() loop

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.