Created
June 24, 2013 18:59
-
-
Save charger/5852536 to your computer and use it in GitHub Desktop.
Yii user register, model&controller example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is the model class for table "{{user}}". | |
* The followings are the available columns in table '{{user}}': | |
* @property integer $id | |
* @property string $login | |
* @property string $pass | |
* @property string $name | |
*/ | |
class tUser extends CActiveRecord { | |
public static function model($className=__CLASS__){ return parent::model($className);} | |
public function tableName() { return '{{site_users}}'; } | |
public $pass2; | |
public function rules() { | |
return array( | |
array('login', 'required'), | |
array('pass', 'required', 'on'=>'login, register'), | |
array('email', 'email'), | |
array('name, pass2', 'safe'), | |
array('pass', 'compare', 'compareAttribute'=>'pass2', 'on'=>'edit, register', 'allowEmpty'=>true), | |
array('pass', 'unsafe', 'on'=>'edit'), | |
array('id, login, pass, name, email', 'safe', 'on'=>'search'), | |
); | |
} | |
public function relations() { | |
return array( | |
); | |
} | |
public function attributeLabels() { | |
return array( | |
'id' => 'ID', | |
'login' => Yii::t('useriada', 'Login'), | |
'pass' => Yii::t('useriada', 'Password'), | |
'pass2' => Yii::t('useriada', 'Repeat password'), | |
'name' => Yii::t('useriada', 'Name'), | |
'email' => Yii::t('useriada', 'E-Mail'), | |
); | |
} | |
public function search() { | |
$criteria=new CDbCriteria; | |
$criteria->compare('id',$this->id); | |
$criteria->compare('login',$this->login,true); | |
$criteria->compare('pass',$this->pass,true); | |
$criteria->compare('name',$this->name,true); | |
$criteria->compare('email',$this->email,true); | |
return new CActiveDataProvider(get_class($this), array( | |
'criteria'=>$criteria, | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment