致命错误:在非对象上调用成员函数saveAs()

时间:2013-08-20 15:29:31

标签: php sql yii

我正在关注本教程:  http://www.yiiframework.com/wiki/349/how-to-upload-image-photo-and-path-entry-in-database-with-update-functionality/#hh0

但我的问题是,当我尝试上传图片时,它会一直这样说:致命错误:在非对象上调用成员函数saveAs()

 */
public function actionCreate()
{
    $model=new Imagem;

    // Uncomment the following line if AJAX validation is needed
    // $this->performAjaxValidation($model);

    if(isset($_POST['Imagem']))
    {
        $rnd = rand(0,9999);
        $model->attributes=$_POST['Imagem'];
        $uploadedFile=CUploadedFile::getInstance($model,'image');
        $fileName = "{$rnd}-{$uploadedFile}";
        if($model->save()){
             **$uploadedFile->saveAs(Yii::app()->basePath.'/../imagem/'.$fileName);** 
             $this->redirect(array('admin'));
        }
    }

    $this->render('create',array(
        'model'=>$model,
    ));
}

粗体是产生如此多问题的代码片段,我在互联网上搜索但所提供的所有解决方案都没有解决任何问题。

0 个答案:

没有答案