Mymodel:
<?php
/**
* This is the model class for table "user".
*
* The followings are the available columns in table 'user':
* @property integer $iduser
* @property string $nome
* @property string $username
* @property string $pass
* @property string $lastLogin
* @property string $email
* @property string $createDate
* @property string $country
* @property integer $receivenews
*
* The followings are the available model relations:
* @property Encomenda[] $encomendas
* @property Authitem[] $authitems
*/
class User extends StyleStoreActiveRecord {
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return User 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 'user';
}
/**
* perform one-way encryption on the password before we store it in
the database
*/
protected function afterValidate() {
parent::afterValidate();
$this->pass = $this->encrypt($this->pass);
}
public function encrypt($value) {
return md5($value);
}
/**
* @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('nome, username, email', 'required'),
array('pass', 'required', 'on' => 'create'),
array('receivenews', 'numerical', 'integerOnly' => true),
array('username,email', 'unique'),
array('nome, email', 'length', 'max' => 145),
array('username', 'length', 'max' => 45),
array('pass', 'length', 'max' => 95),
array('pass', 'required', 'on' => 'create'),
array('iduser, nome, username, pass,country,receivenews, lastLogin, email, createDate', '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(
'encomendas' => array(self::HAS_MANY, 'Encomenda', 'customer'),
);
}
public function afterSave() {
if ($this->isNewRecord) {
$role = new UserRole;
$role->idUser = $this->iduser;
$role->RoleName = 'Customer';
$role->addRole();
$role->save();
}
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels() {
return array(
'iduser' => 'Iduser',
'nome' => Yii::t('app', 'Name'),
'username' => Yii::t('app', 'Username'),
'pass' => Yii::t('app', 'Password'),
'lastLogin' => Yii::t('app', 'Last Login'),
'email' => 'Email',
'country' => 'Country',
'receivenews' => Yii::t('app', 'Stay tuned about new styles'),
'createDate' => Yii::t('app', 'Create 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('iduser', $this->iduser);
$criteria->compare('nome', $this->nome, true);
$criteria->compare('username', $this->username, true);
$criteria->compare('pass', $this->pass, true);
$criteria->compare('lastLogin', $this->lastLogin, true);
$criteria->compare('email', $this->email, true);
$criteria->compare('country', $this->country, true);
$criteria->compare('receivenews', $this->receivenews);
$criteria->compare('createDate', $this->createDate, true);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
}
view:
CHtml::activeDropDownList($model,' country', $this->getPaises())
why i get Property "User. country" is not defined.