Я использую Yii Framework и хочу создать страницу регистрации пользователя. Кажется, все работает нормально, но когда я хочу загрузить изображение пользователя, я получаю сообщение об ошибке:
include(Self.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
Вот мой код SiteController:
public function actionRegister()
{
$model=new RegisterForm;
// uncomment the following code to enable ajax-based validation
if(isset($_POST['ajax']) && $_POST['ajax']==='register-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
if(isset($_POST['RegisterForm']))
{
$model->attributes=$_POST['RegisterForm'];
if($model->validate())
{
$user = new User;
$user->username = $_POST['RegisterForm']['username'];
$password = $_POST['RegisterForm']['password'];
$salt = Security::GenerateSalt(128);
$user->password = hash('sha512', $password.$salt);
$user->question = $_POST['RegisterForm']['question'];
$user->answer = $_POST['RegisterForm']['answer'];
$user->salt = $salt;
$user->email = $_POST['RegisterForm']['email'];
$user->fullname = $_POST['RegisterForm']['fullname'];
$user->birth = $_POST['RegisterForm']['birth'];
$user->avatar = CUploadedFile::getInstance($model,'image');
$user->avatar->saveAs('/images/users.test.jpg');
$user->about = $_POST['RegisterForm']['about'];
$user->signup = date('d/m/y');
$user->login = date('d/m/y');
$user->save();
}
}
$this->render('register',array('model'=>$model));
}
Вот мой код модели RegisterForm:
<?php
class RegisterForm extends CFormModel
{
[.....]
public $avatar;
[.....]
public function rules()
{
return array(
[......]
array('avatar', 'file',
'types'=>'jpg, gif, png',
'maxSize'=>1024 * 1024 * 2,
'tooLarge'=>'The file was larger than 2MB. Please upload a smaller file.',
'wrongType'=>'Please upload only images in the format jpg, gif, png',
'tooMany'=>'You can upload only 1 avatar',
'on'=>'upload'),
[......]
}
Вид:
<div class="row">
<?php echo $form->labelEx($model,'avatar'); ?>
<?php echo CHtml::activeFileField($model, 'avatar'); ?>
<?php echo $form->error($model,'avatar'); ?>
</div>