dpjj4763 2013-09-11 11:11 采纳率: 0%
浏览 87
已采纳

从两个模型中显示Yii Gridview中的计数数据

I have 2 tables, servers and ip, in ip table I am saving server_id. Now I want to show on server listing page how many total ips related to one server?

MY Server model code:

   class Server extends CActiveRecord {

        public function relations(){
     return array('ipmodel'=>array(self::BELONGS_TO, 'IpManager', 'server_id'),
        );
       }
     }

My CGridView Code:

     array( 
        'header' => 'IP Count',
        'value' => 'count($data->ipmodel)',
     ),

It is showing only 1 but there are so many ips against to one server! How I can do this?

  • 写回答

2条回答 默认 最新

  • doubu1853 2013-09-11 11:18
    关注

    Change relation!

          'ipmodel'=>array(self::HAS_MANY, 'IpManager', 'server_id')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?