2012-03-01 6 views
0

私はYiiフレームワークを使用しています。ユーザー登録ページを作成します。すべてが正常に動作するようですが、私は、ユーザーが画像をアップロードするとき、私はエラーメッセージを得る:ここでYiiフレームワークがストリームを開けませんでした

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> 

答えて

2

ディレクトリ権限の問題である可能性があります。それが正しいかどうかを確認するには、

chmod 0777 <dir_name> 

確かに、適切にアクセス権をリセットすることができます。

+0

いいえ、私は単純な問題を発見しました。私は静的関数を使用しています。このようなクラスの中ではself >> testFunction();を呼び出していました。それは間違っているようですので、どのように正しい形式ですか? – Irakli

+0

クラス名がAならば、静的関数をクラス名で呼び出すことができます。 A :: testFunction() –

+0

しかし、静的関数がAの場合はAから呼び出したいですか? $ this-> testFunction();は、同じクラスの内側から – Irakli

関連する問題