简体   繁体   English

Yii Counter查询Findall

[英]Yii counter query in findall

I have the following query 我有以下查询

UserLogin::model()
-> with(array(
    'Provider'=> array(
        'select'=>'name'
    )
))
-> findAll(array(
    'select' => 'count(t.id) as count ',
    'group'=>'provider_id',
    'order'=>'provider_id'
));

and my view is 我的看法是

<?php foreach($providerCounts as $providerCount): ?>
    <tr>
        <td><?php echo $providerCount['Provider']['name']; ?></td>
        <td><?php echo $providerCount['count']; ?></td>             
    </tr>
<?php endforeach; ?>

Here is the relation 这是关系

'Provider'=>array(self::BELONGS_TO, 'Provider', 'provider_id'),

I am getting the error 我收到错误

Property "UserLogin.counts" is not defined. 未定义属性“ UserLogin.counts”。

The same query in a different model is working. 不同模型中的相同查询正在运行。

Now i have two question 现在我有两个问题

  • Why is the query not working 为什么查询不起作用
  • How do i debug such errors in yii 我如何在yii中调试此类错误

您需要具有UserLogin.count属性,以便当您在AR请求中使用as时,Yii可以将返回的DB值分配给模型。

You need specify public property count 您需要指定公共财产计数

class UserLogin extends CActiveRecord
{
    public $count = 0;

    public function rules() {
        // ...
        array('count', 'safe'),
        // ...
    }
}

For debug use xdebug for php + ext for FireFox for debugging php 对于调试,请使用xdebug for php + ext用于FireFox调试php

Also use yii-debug-toolbar (search in yii ext site) 还可以使用yii-debug-toolbar (在yii ext网站中搜索)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM