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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:42:09+00:00 2026-06-06T05:42:09+00:00

I’m trying to make a cgridview that can filter data from relations table. This

  • 0

I’m trying to make a cgridview that can filter data from relations table. This is my first time with CGridView and I just can’t get it to work. Help is appreciated.
I have 2 problems. first: i have managed to get a dropdown filter of my users (avtor, relation in Novica), but when I choose one, it always returns this: “No results found.”.
second: When I try to filter with Novica.ID, i get this error: (filtering with other columsn works great)

Error 500:

CDbException

CDbCommand failed to execute the
SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052
Column ‘id’ in where clause is ambiguous. The SQL statement executed
was: SELECT COUNT(*) FROM novica t LEFT OUTER JOIN uporabnik
avtor ON (t.uporabnik_id=avtor.id) WHERE ((uporabnik_id =
:id) AND (id=:ycp0))
(C:\xampp\htdocs\PEF\framework\db\CDbCommand.php:528)

0
C:\xampp\htdocs\PEF\framework\db\CDbCommand.php(425):
CDbCommand->queryInternal('fetchColumn', 0, Array) 1
C:\xampp\htdocs\PEF\framework\db\ar\CActiveFinder.php(762):
CDbCommand->queryScalar() 2
C:\xampp\htdocs\PEF\framework\db\ar\CActiveFinder.php(155):
CJoinElement->count(Object(CDbCriteria)) 3
C:\xampp\htdocs\PEF\framework\db\ar\CActiveRecord.php(1540):
CActiveFinder->count(Object(CDbCriteria)) 4
C:\xampp\htdocs\PEF\framework\web\CActiveDataProvider.php(179):
CActiveRecord->count(Object(CDbCriteria)) 5
C:\xampp\htdocs\PEF\framework\web\CDataProvider.php(193):
CActiveDataProvider->calculateTotalItemCount() 6
C:\xampp\htdocs\PEF\framework\web\CActiveDataProvider.php(129):
CDataProvider->getTotalItemCount() 7
C:\xampp\htdocs\PEF\framework\web\CDataProvider.php(137):
CActiveDataProvider->fetchData() 8
C:\xampp\htdocs\PEF\framework\zii\widgets\CBaseListView.php(105):
CDataProvider->getData() 9
C:\xampp\htdocs\PEF\framework\zii\widgets\grid\CGridView.php(269):
CBaseListView->init() 10
C:\xampp\htdocs\PEF\framework\web\CBaseController.php(148):
CGridView->init() 11
C:\xampp\htdocs\PEF\framework\web\CBaseController.php(173):
CBaseController->createWidget('zii.widgets.gri...', Array) 12
C:\xampp\htdocs\PEF\protected\views\adminNovica\index.php(28):
CBaseController->widget('zii.widgets.gri...', Array) 13
C:\xampp\htdocs\PEF\framework\web\CBaseController.php(127):
require('C:\xampp\htdocs...') 14
C:\xampp\htdocs\PEF\framework\web\CBaseController.php(96):
CBaseController->renderInternal('C:\xampp\htdocs...', Array, true) 15
C:\xampp\htdocs\PEF\framework\web\CController.php(870):
CBaseController->renderFile('C:\xampp\htdocs...', Array, true) 16
C:\xampp\htdocs\PEF\protected\controllers\AdminNovicaController.php(19):
CController->renderPartial('index', Array) 17
C:\xampp\htdocs\PEF\framework\web\actions\CInlineAction.php(50):
AdminNovicaController->actionIndex() 18
C:\xampp\htdocs\PEF\framework\web\CController.php(309):
CInlineAction->runWithParams(Array) 19
C:\xampp\htdocs\PEF\framework\web\CController.php(287):
CController->runAction(Object(CInlineAction)) 20
C:\xampp\htdocs\PEF\framework\web\CController.php(266):
CController->runActionWithFilters(Object(CInlineAction), Array) 21
C:\xampp\htdocs\PEF\framework\web\CWebApplication.php(276):
CController->run('') 22
C:\xampp\htdocs\PEF\framework\web\CWebApplication.php(135):
CWebApplication->runController('adminnovica') 23
C:\xampp\htdocs\PEF\framework\base\CApplication.php(162):
CWebApplication->processRequest() 24
C:\xampp\htdocs\PEF\index.php(13): CApplication->run() 25 {main}

These are my tables:

er

Models:
Novica (eng: News)

public function relations() {
        return array(
            'uporabnik' => array(self::BELONGS_TO, 'DostopNovica', 'uporabnik_id'),
            'avtor' => array(self::BELONGS_TO, 'Uporabnik', 'uporabnik_id'),
        );
    }

public function search() {
        $criteria = new CDbCriteria;
        $criteria->compare('id', $this->id);
        $criteria->with = 'avtor';
        $criteria->compare('naslov', $this->naslov, true);
        $criteria->compare('datum', $this->datum, true);
        $criteria->compare('avtor.upime', $this->uporabnik_id, true); //avtor.upime (eng. author.username)

    return new CActiveDataProvider(get_class($this), array(
                'criteria' => $criteria,
                'sort' => array(
                    'defaultOrder' => 'datum DESC', //date
                ),
                'pagination' => array(
                    'pageSize' => 5
                ),
            ));
}

Action:

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

            $params = array(
                'model' => $model,
            );

            if (!isset($_GET['ajax']))
                $this->render('index', $params);
            else
                $this->renderPartial('index', $params);
        }

CGridView:

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array('id',
        array('name' => 'datum',
            'value' => 'date("j.n.Y G:i", strtotime($data->datum))'
        ),
        array(
            'name' => 'uporabnik_id',
            'value' => 'Uporabnik::Model()->FindByPk($data->uporabnik_id)->upime',
            'filter' => CHtml::listData(Uporabnik::model()->findAll(), 'id', 'upime'),
        ),
        'naslov'
    //specify the colums you wanted here
    ),
));
  • 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-06T05:42:10+00:00Added an answer on June 6, 2026 at 5:42 am

    Problem 1:

    In your model use

    $criteria->compare('avtor.id', $this->uporabnik_id, true);

    compare with id of relation avtor because that is what you have defined as value in dropdown in your gridview..CHtml::listData(Uporabnik::model()->findAll(), 'id', 'upime')..listData syntex is models, value, text..

    Problem 2:

    In your model use

    $criteria->compare('t.id', $this->id);

    t is the default alias used by the yii for the table…the problem with ambigious is that column id exists in both tables..

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.