我是 yii 框架的新手。我有 3 个表,表 A,表 B,表 C。表 A 和表 B 与主键和外键关系相关。表 B 和表 C 与主键和外键关系链接的方式相同。我想显示,过滤管理页面的 cgridview 中的数据..使用 yii fra 更新:我有 3 个models.subscriber.php、assignment.php、groups.php 我想显示 3 个模型的属性并在subscriber.php 的 cgridview 中显示它们???
订阅者.php.......
/**
* This is the model class for table "users_phone_numbers".
*
* The followings are the available columns in table 'users_phone_numbers':
* @property integer $id
* @property string $name
* @property string $phone_number
* @property integer $created_user
* @property string $created_date
* @property integer $modified_user
* @property string $modified_date
* @property integer $status
* @property string $message_type
* @property string $birthdate
* @property string $email
*
* The followings are the available model relations:
* @property PhoneNumberGroupAssignment[] $phoneNumberGroupAssignments
*/
class subscriber extends CActiveRecord
{
//public $group_search; //for searching and displaying in cgridview
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return subscriber the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'users_phone_numbers';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('phone_number, created_user, created_date, birthdate, email', 'required'),
array('created_user, modified_user, status', 'numerical', 'integerOnly'=>true),
array('name, phone_number', 'length', 'max'=>100),
array('message_type', 'length', 'max'=>20),
array('email', 'length', 'max'=>150),
array('modified_date', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, name, phone_number, created_user, created_date, modified_user, modified_date, status, message_type, birthdate, email ', 'safe', 'on'=>'search'),//add above defined variable.
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'phoneNumberGroupAssignments' => array(self::HAS_MANY, 'Assignment', 'phone_number_id'),
//'postCount' => array(self::STAT, 'assignment', 'phone_number_id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'name' => 'Name',
'phone_number' => 'Phone Number',
'created_user' => 'Created User',
'created_date' => 'Created Date',
'modified_user' => 'Modified User',
'modified_date' => 'Modified Date',
'status' => 'Status',
'message_type' => 'Message Type',
'birthdate' => 'Birthdate',
'email' => 'Email',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
//$criteria->with = array( 'phoneNumberGroupAssignments' ); //new
$criteria->compare('id',$this->id);
$criteria->compare('name',$this->name,true);
$criteria->compare('phone_number',$this->phone_number,true);
$criteria->compare('created_user',$this->created_user);
$criteria->compare('created_date',$this->created_date,true);
$criteria->compare('modified_user',$this->modified_user);
$criteria->compare('modified_date',$this->modified_date,true);
$criteria->compare('status',$this->status);
$criteria->compare('message_type',$this->message_type,true);
$criteria->compare('birthdate',$this->birthdate,true);
$criteria->compare('email',$this->email,true);
//$criteria->compare( 'phoneNumberGroupAssignments.group_id', $this->group_search, true );
return new CActiveDataProvider($this, array('criteria'=>$criteria,
/*'sort'=>array(
'attributes'=>array(
'group_search'=>array(
'asc'=>'phoneNumberGroupAssignments.group_id',
'desc'=>'phoneNumberGroupAssignments.group_id DESC',
),
),
),
*/
));
}
}
第二个任务.php
/**
* This is the model class for table "phone_number_group_assignment".
*
* The followings are the available columns in table 'phone_number_group_assignment':
* @property integer $id
* @property integer $phone_number_id
* @property integer $group_id
* @property integer $created_user
* @property string $created_date
* @property integer $modified_user
* @property string $modified_date
*
* The followings are the available model relations:
* @property UsersPhoneNumbers $phoneNumber
*/
class assignment extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return assignment the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'phone_number_group_assignment';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('phone_number_id, group_id, created_date', 'required'),
array('phone_number_id, group_id, created_user, modified_user', 'numerical', 'integerOnly'=>true),
array('modified_date', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, phone_number_id, group_id, created_user, created_date, modified_user, modified_date', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'phoneNumber' => array(self::BELONGS_TO, 'Subscriber', 'phone_number_id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'phone_number_id' => 'Phone Number',
'group_id' => 'Group',
'created_user' => 'Created User',
'created_date' => 'Created Date',
'modified_user' => 'Modified User',
'modified_date' => 'Modified Date',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('phone_number_id',$this->phone_number_id);
$criteria->compare('group_id',$this->group_id);
$criteria->compare('created_user',$this->created_user);
$criteria->compare('created_date',$this->created_date,true);
$criteria->compare('modified_user',$this->modified_user);
$criteria->compare('modified_date',$this->modified_date,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
第三个:groups.php
/**
* This is the model class for table "client_groups".
*
* The followings are the available columns in table 'client_groups':
* @property integer $id
* @property integer $client_id
* @property string $title
* @property string $keywords
* @property integer $status
* @property integer $created_user
* @property string $created_date
* @property integer $modified_user
* @property string $modified_date
* @property integer $is_default
* @property integer $is_special_group
* @property string $back_office_no
* @property string $special_group_sms_text
* @property string $text_sms_office
* @property string $day_delay_1
* @property string $subscription_sms_1
* @property string $day_delay_2
* @property string $subscription_sms_2
* @property string $day_delay_3
* @property string $subscription_sms_3
* @property string $campaign_sms
* @property string $delay_time_1
* @property string $delay_time_2
* @property string $delay_time_3
* @property integer $msg_counter
* @property integer $msg_counter_start_num
* @property integer $add_expiry
* @property integer $add_days
* @property integer $phone_number_id
* @property integer $ar_type
* @property string $email
*
* The followings are the available model relations:
* @property ClientInformation $client
*/
class Groups extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Groups the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'client_groups';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('client_id, created_user, created_date, msg_counter, add_expiry, add_days, phone_number_id, ar_type, email', 'required'),
array('client_id, status, created_user, modified_user, is_default, is_special_group, msg_counter, msg_counter_start_num, add_expiry, add_days, phone_number_id, ar_type', 'numerical', 'integerOnly'=>true),
array('title', 'length', 'max'=>250),
array('keywords', 'length', 'max'=>255),
array('back_office_no', 'length', 'max'=>50),
array('day_delay_1, day_delay_2, day_delay_3', 'length', 'max'=>3),
array('subscription_sms_1, subscription_sms_2, subscription_sms_3, campaign_sms, email', 'length', 'max'=>200),
array('modified_date, special_group_sms_text, text_sms_office, delay_time_1, delay_time_2, delay_time_3', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, client_id, title, keywords, status, created_user, created_date, modified_user, modified_date, is_default, is_special_group, back_office_no, special_group_sms_text, text_sms_office, day_delay_1, subscription_sms_1, day_delay_2, subscription_sms_2, day_delay_3, subscription_sms_3, campaign_sms, delay_time_1, delay_time_2, delay_time_3, msg_counter, msg_counter_start_num, add_expiry, add_days, phone_number_id, ar_type, email', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'client' => array(self::BELONGS_TO, 'ClientInformation', 'client_id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'client_id' => 'Client',
'title' => 'Title',
'keywords' => 'Keywords',
'status' => 'Status',
'created_user' => 'Created User',
'created_date' => 'Created Date',
'modified_user' => 'Modified User',
'modified_date' => 'Modified Date',
'is_default' => 'Is Default',
'is_special_group' => 'Is Special Group',
'back_office_no' => 'Back Office No',
'special_group_sms_text' => 'Special Group Sms Text',
'text_sms_office' => 'Text Sms Office',
'day_delay_1' => 'Day Delay 1',
'subscription_sms_1' => 'Subscription Sms 1',
'day_delay_2' => 'Day Delay 2',
'subscription_sms_2' => 'Subscription Sms 2',
'day_delay_3' => 'Day Delay 3',
'subscription_sms_3' => 'Subscription Sms 3',
'campaign_sms' => 'Campaign Sms',
'delay_time_1' => 'Delay Time 1',
'delay_time_2' => 'Delay Time 2',
'delay_time_3' => 'Delay Time 3',
'msg_counter' => 'Msg Counter',
'msg_counter_start_num' => 'Msg Counter Start Num',
'add_expiry' => 'Add Expiry',
'add_days' => 'Add Days',
'phone_number_id' => 'Phone Number',
'ar_type' => 'Ar Type',
'email' => 'Email',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('client_id',$this->client_id);
$criteria->compare('title',$this->title,true);
$criteria->compare('keywords',$this->keywords,true);
$criteria->compare('status',$this->status);
$criteria->compare('created_user',$this->created_user);
$criteria->compare('created_date',$this->created_date,true);
$criteria->compare('modified_user',$this->modified_user);
$criteria->compare('modified_date',$this->modified_date,true);
$criteria->compare('is_default',$this->is_default);
$criteria->compare('is_special_group',$this->is_special_group);
$criteria->compare('back_office_no',$this->back_office_no,true);
$criteria->compare('special_group_sms_text',$this->special_group_sms_text,true);
$criteria->compare('text_sms_office',$this->text_sms_office,true);
$criteria->compare('day_delay_1',$this->day_delay_1,true);
$criteria->compare('subscription_sms_1',$this->subscription_sms_1,true);
$criteria->compare('day_delay_2',$this->day_delay_2,true);
$criteria->compare('subscription_sms_2',$this->subscription_sms_2,true);
$criteria->compare('day_delay_3',$this->day_delay_3,true);
$criteria->compare('subscription_sms_3',$this->subscription_sms_3,true);
$criteria->compare('campaign_sms',$this->campaign_sms,true);
$criteria->compare('delay_time_1',$this->delay_time_1,true);
$criteria->compare('delay_time_2',$this->delay_time_2,true);
$criteria->compare('delay_time_3',$this->delay_time_3,true);
$criteria->compare('msg_counter',$this->msg_counter);
$criteria->compare('msg_counter_start_num',$this->msg_counter_start_num);
$criteria->compare('add_expiry',$this->add_expiry);
$criteria->compare('add_days',$this->add_days);
$criteria->compare('phone_number_id',$this->phone_number_id);
$criteria->compare('ar_type',$this->ar_type);
$criteria->compare('email',$this->email,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
当前的 cgrid 视图正在从两个模型(assignemnt 和subscriber)访问数据,而不是从组访问数据。并且它给出了试图获取非对象属性的错误
C:\wamp\www\yii\framework\base\CComponent.php(607) : eval()'d code(1) ..so 请检查 2 和 3 模型?需要紧急帮助。谢谢