Здравствуйте только начал изучать Yii . Можете проверить правильно ли я организовал регистрацию или правильнее было бы каким-то другим методом.
Модель Users
<?php
/**
* Description of User
*
* @author like2dev
*/
class User extends CActiveRecord {
public $verifyCode;
public $passwd2;
public static function model($className = __CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'user';
}
public function rules()
{
return array(
array('login, passwd', 'length', 'max'=>15, 'min' => 4),
array('login, passwd', 'required'),
array('login','unique'),
array('passwd2', 'required', 'on'=>'registration'),
array('passwd', 'compare', 'compareAttribute'=>'passwd2', 'on'=>'registration'),
array('verifyCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd')),
array('login', 'match', 'pattern' => '/^[A-Za-z0-9А-Яа-я\s,]+$/u','message' => 'Логин содержит недопустимые символы.'),
);
}
public function attributeLabels()
{
return array(
'login' => 'Логин',
'passwd' => 'Пароль',
'passwd2' => 'Повторный пароль пароль',
);
}
/* Че то не работает <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' /> */
public function onBeforeSave() {
$this->setAttribute("passwd", md5($passwd));
$this->setAttribute("created", date("Y-m-d H:i:s"));
}
}
UserController
<?php
/**
* Description of UserController
*
* @author like2dev
*/
class UserController extends CController {
public function actions()
{
return array (
'captcha' => array(
'class' => 'CCaptchaAction',
'backColor' => 0x003300,
'minLength' => 3,
'maxLength' => 3,
'foreColor' => 0x66FF66,
),
);
}
public function actionLogin()
{
}
public function actionLogout()
{
}
public function actionRegistration()
{
$form = new User();
if (!Yii::app()->user->isGuest) {
throw new CException('Вы уже зарегистрированны!');
} else {
if (!empty($_POST['User'])) {
$form->attributes = $_POST['User'];
$form->verifyCode = $_POST['User']['verifyCode'];
$form->passwd2 = $_POST['User']['passwd2'];
$form->setScenario('registration');
if($form->validate()) {
$form->save();
$this->render("registration_ok",array('data' => $form->attributes));
} else {
$this->render("registration", array('form' => $form));
}
} else {
$this->render("registration", array('form' => $form));
}
}
}
}
в View элементы форм создаю через actionTextField e.t.c