jjzjj

php - 合并两个 CActiveDataProvider 并在 yii 的 CGridview 中显示结果

coder 2024-05-03 原文

我有 2 个模型:

 $model = new ProfileInformation('internetConection');
 $modeliner = new ProfileInformation('inerConection');

我在 2 CGridView 中显示那些在 yii 中如何显示在 CGridView 中

型号:

 public function internetConection() {
        // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria = new CDbcriteria();
    $criteria->with = array('user');
    $criteria->condition = 'serviceId=:serviceId';
    $criteria->params = array(':serviceId' => '1');
    $criteria->group = 't.user_Id';
    $criteria->select = array('count(distinct psh_profile_information_services.profileInformationId) AS internetConectionCount');
    $criteria->join = 'left join psh_profile_information_services on t.id=psh_profile_information_services.profileInformationId';
    $criteria->order = 't.id';
    $criteria->compare('user_Id', $this->user_Id);
    $criteria->compare('isService', $this->isService, true);


    return new CActiveDataProvider($this, array(
        'criteria' => $criteria,
    ));
}

public function inerConection() {
    // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria = new CDbcriteria();
    $criteria->with = array('user');
    $criteria->addInCondition('serviceId', array(2, 3, 4, 5));
    $criteria->group = 't.user_Id';
    $criteria->select = array('count(distinct psh_profile_information_services.profileInformationId) AS inerConectionCount');
    $criteria->join = 'left join psh_profile_information_services on t.id=psh_profile_information_services.profileInformationId';
    $criteria->order = 't.id';
    $criteria->compare('user_Id', $this->user_Id);
    $criteria->compare('isService', $this->isService, true);


    return new CActiveDataProvider($this, array(
        'criteria' => $criteria,
    ));
}

我现在正在使用 2 个 CgridView,但如果我能在表格中显示它就很好了。 每个结果搜索都有一个新字段:inerConectionCount 和 internetConectionCount。

internetConectionCount 表
inernetConectionCount 表

我想要它:

 $this->widget('zii.widgets.grid.CGridView', array(
        'id' => 'profile-information-grid1',
        'dataProvider' => $dataprovider
            'columns' => array(
            array(
                'header' => '',
                'value' => '$this->grid->dataProvider->pagination->offset + $row+1', //  row is zero based
            ),

             array(
                'name' => 'ProfileInformation.user.organization',
                'value' => 'CHtml::encode($data->user->organization)',

            ),

            array(
                'name' => 'ProfileInformation.user.scope',
                'value' => 'CHtml::encode($data->user->scope->name)',
                'filter' => Scope::model()->options,
            ),
            array(
                'name' => 'id',
                'value' => 'CHtml::encode($data->id)',
            ),

          'inerConectionCount',



        ),
    ));

最佳答案

您可以合并来自两个提供者的数据,但您必须禁用分页,否则每个提供者将限制为 10 条记录

$model = new ProfileInformation('internetConection');
$modeliner = new ProfileInformation('inerConection');

$data = CMap::mergeArray( // combine two data
    $model->search()->getData(),
    $modeliner ->search()->getData()
);

$provider = new CArrayDataProvider( $data ); // use CArrayDataProvider instead of CActiveDataProvider

关于php - 合并两个 CActiveDataProvider 并在 yii 的 CGridview 中显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24504780/

有关php - 合并两个 CActiveDataProvider 并在 yii 的 CGridview 中显示结果的更多相关文章

  1. ruby-on-rails - Rails 编辑表单不显示嵌套项 - 2

    我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib

  2. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  3. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

    exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

  4. ruby-on-rails - 使用 Sublime Text 3 突出显示 HTML 背景语法中的 ERB? - 2

    所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择

  5. ruby - 如果指定键的值在数组中相同,如何合并哈希 - 2

    我有一个这样的哈希数组:[{:foo=>2,:date=>Sat,01Sep2014},{:foo2=>2,:date=>Sat,02Sep2014},{:foo3=>3,:date=>Sat,01Sep2014},{:foo4=>4,:date=>Sat,03Sep2014},{:foo5=>5,:date=>Sat,02Sep2014}]如果:date相同,我想合并哈希值。我对上面数组的期望是:[{:foo=>2,:foo3=>3,:date=>Sat,01Sep2014},{:foo2=>2,:foo5=>5:date=>Sat,02Sep2014},{:foo4=>4,:dat

  6. ruby-on-rails - link_to 不显示任何 rails - 2

    我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article

  7. ruby-on-rails - 如何在 Rails View 上显示错误消息? - 2

    我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c

  8. ruby - 这两个 Ruby 类初始化定义有什么区别? - 2

    我正在阅读一本关于Ruby的书,作者在编写类初始化定义时使用的形式与他在本书前几节中使用的形式略有不同。它看起来像这样:classTicketattr_accessor:venue,:datedefinitialize(venue,date)self.venue=venueself.date=dateendend在本书的前几节中,它的定义如下:classTicketattr_accessor:venue,:datedefinitialize(venue,date)@venue=venue@date=dateendend在第一个示例中使用setter方法与在第二个示例中使用实例变量之间是

  9. 报告回顾丨模型进化狂飙,DetectGPT能否识别最新模型生成结果? - 2

    导读语言模型给我们的生产生活带来了极大便利,但同时不少人也利用他们从事作弊工作。如何规避这些难辨真伪的文字所产生的负面影响也成为一大难题。在3月9日智源Live第33期活动「DetectGPT:判断文本是否为机器生成的工具」中,主讲人Eric为我们讲解了DetectGPT工作背后的思路——一种基于概率曲率检测的用于检测模型生成文本的工具,它可以帮助我们更好地分辨文章的来源和可信度,对保护信息真实、防止欺诈等方面具有重要意义。本次报告主要围绕其功能,实现和效果等展开。(文末点击“阅读原文”,查看活动回放。)Ericmitchell斯坦福大学计算机系四年级博士生,由ChelseaFinn和Chri

  10. ruby-on-rails - 复数 for fields_for has_many 关联未显示在 View 中 - 2

    目前,Itembelongs_toCompany和has_manyItemVariants。我正在尝试使用嵌套的fields_for通过Item表单添加ItemVariant字段,但是使用:item_variants不显示该表单。只有当我使用单数时才会显示。我检查了我的关联,它们似乎是正确的,这可能与嵌套在公司下的项目有关,还是我遗漏了其他东西?提前致谢。注意:下面的代码片段中省略了不相关的代码。编辑:不知道这是否相关,但我正在使用CanCan进行身份验证。routes.rbresources:companiesdoresources:itemsenditem.rbclassItemi

随机推荐