[ create a new paste ] login | about

Link: http://codepad.org/iI3Xzgun    [ raw code | output | fork ]

PHP, pasted on Aug 12:
<?php
/*Контроллер*/
class LoginController extends Controller
{    
    public function actionRegister()
    {
        $model = new RegisterForm;
        
        if(!empty($_POST['RegisterForm']))
        {
            $model->attributes = $_POST['RegisterForm'];
            
            if($model->validate() && $model->register())
                $this->redirect($this->createUrl('site/index'));
                
        }
        
        $this->render('register', array('model'=>$model));
    }
    
}

/*Модель Регистрации*/
class RegisterForm extends CFormModel
{
    public $email;
    public $password, $password2;

    public function rules()
    {
        return array(
            array('email, password, password2', 'required', 'message'=>'Поле обязательно для заполнения'),
            array('email', 'email', 'message'=>'Неверный формат Email'),
            array('password', 'compare', 'compareAttribute'=>'password2', 'message'=>'Пароли не совпадают'),
        );
    }
    
    public function register()
    {
        if(!$this->hasError())
        {
            
            //Добавляем в бд
            $model = new User;
            $model->user_email = $this->email;
            $model->user_password = CPasswordHelper::hashPassword($this->password);
            $model->save();
            
        }
        else
            return false;
    }
}

/*Модель User*/
class User extends CActiveRecord
{
    public function tableName()
    {
        return 'user';
    }

    public function rules()
    {
        return array(
            array('user_email, user_password', 'required'),
            array('user_email', 'length', 'max'=>50),
            array('user_password', 'length', 'max'=>60),
        );
    }

    public function relations()
    {
        return array();
    }
    
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }
}


Output:
1
2

Fatal error: Class 'Controller' not found on line 3


Create a new paste based on this one


Comments: