1
我試圖爲蒙戈集合創建動態模型類和Cgridview填充數據(使用YIIMongodbsuite擴展)創建動態屬性蒙戈系列 - Yii框架
獲取列從MySQL數據庫:
$sql="SELECT name FROM CRM_Field Where crm_base_contact_id = ".$base;
$names =Yii::app()->db->createCommand($sql)->query()-> readAll();
鑑於訪問型號:
$cc = new ContactCollection($names);// Passing dynamic column names to Model
$criteria = new EMongoCriteria;
$criteria->crm_base_contact_id('==', $base);
$cc->setDbCriteria($criteria);
CgridView代碼:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id' =>'BCImported-grid',
'dataProvider' => $cc->search(false),
'columns' => $names,
)); ?>
ContactCollection型號:
<?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;
}
}
我收到此錯誤" Property "ContactCollection.0" is not defined."
你在哪裏得到這個錯誤?另外,如果您使用YIIMongodbsuite,請查看EMongoSoftDocument,它完全正是您在這裏要做的。 – Blizz