Yii Framework Forum: Creating Dynamic Attributes For Mongo Collection - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Creating Dynamic Attributes For Mongo Collection Rate Topic: -----

#1 User is offline   Ayyanar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 24-December 13

Posted 12 January 2014 - 10:17 PM

I am trying to create dynamic model class for Mongo Collection and populate data in Cgridview (using YIIMongodbsuite extension)

Getting Column from MySQL DB:

$sql="SELECT name FROM CRM_Field Where crm_base_contact_id = ".$base;
$names =Yii::app()->db->createCommand($sql)->query()-> readAll();


Accessing Model in view:

$cc = new ContactCollection($names);// Passing dynamic column names to Model 
 $criteria = new EMongoCriteria;
 $criteria->crm_base_contact_id('==', $base);
 $cc->setDbCriteria($criteria);

 <?php $this->widget('zii.widgets.grid.CGridView', array(
    'id' =>'BCImported-grid',
    'dataProvider' => $cc->search(false),
    'columns' => $names,
        )); ?>


ContactCollection Model :

<?php
class ContactCollection extends EMongoDocument
    {
        public $dyn_fields;
   public function __construct ($names) {
        $this->dyn_fields = $names;

    }

  public function getCollectionName()
      {
        return 'cartoons';
      }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        $allMembers = implode(', ', array_keys($this->dyn_fields));
        return array(
            array($allMembers, 'required'),
        );
    }

    public function attributeLabels()
    {
       return $this->dyn_fields;
    }
    }


In grid im getting empty rows(shown in attacment) but number of row count is correct,how to populate rows with mongo data,where im doing wrong???

Attached File(s)

  • Attached File  Grid.PNG (13.83K)
    Number of downloads: 5

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users