Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法设置不安全的属性上载yii_Yii - Fatal编程技术网

无法设置不安全的属性上载yii

无法设置不安全的属性上载yii,yii,Yii,上传图像已经造成了很多麻烦。我总是有两个问题。首先,当使用文件夹中的asset manager时,它总是无法上载或无法找到文件!!所以当我的控制器说取消文件链接时,它不会取消任何链接。其次,当我的规则设置为安全时,它将显示设置不安全属性失败 这是我的规则: array('product_image,product_gallery_1, product_gallery_2, product_gallery_3, product_gallery_4, product_gallery_5, produ

上传图像已经造成了很多麻烦。我总是有两个问题。首先,当使用文件夹中的asset manager时,它总是无法上载或无法找到文件!!所以当我的控制器说取消文件链接时,它不会取消任何链接。其次,当我的规则设置为安全时,它将显示设置不安全属性失败

这是我的规则:

array('product_image,product_gallery_1, product_gallery_2, product_gallery_3, product_gallery_4, product_gallery_5, product_gallery_6', 'file','types'=>'jpg, jpeg, gif, png','allowEmpty'=>true, 'on'=>'update', 'safe'=>true),
看来我确实有

'htmlOptions'=>array('enctype'=>'multipart/form-data'), 
这里有一节是关于更新控制器的。它确实上载了多个图像:

public function actionUpdate($id)
    {
        $model=$this->loadModel($id);
        $old_img = $model->product_image;

        if(isset($_POST['Product']))
        {
            $model->update_date = time();
            $model->product_approval_status = "N";

            $t_product_image = $model->product_image;
            $model->attributes=$_POST['Product'];

            $product_image=CUploadedFile::getInstance($model,'product_image');

            $storeid = $model->store_id;
            $date = date('mdy');
            $rnd = rand(0,9999);

            $f_product_image = "{$rnd}-{$date}{$storeid}-{$product_image}";  

            //main img
            if(!empty($product_image))
            {
                $model->product_image = $f_product_image;
            }
            else
            {
                if(file_exists(Yii::app()->basePath.'/images/shop/thumbnail/thumb_'.$model->product_image))
                    unlink(Yii::app()->basePath.'/images/shop/thumbnail/thumb_'.$old_img);
                if(file_exists(Yii::app()->basePath.'/images/shop/product/'.$model->product_image)&& ($old_img !==null))
                    unlink(Yii::app()->basePath.'/images/shop/thumbnail/'.$old_img);

                $model->product_image = $t_product_image;
            }

            if($model->save())
            {
                $url = Yii::app()->basePath.'/images/shop/product/';
                $thumb = Yii::app()->basePath.'/images/shop/thumbnail/';
                if(!empty($product_image))
                {
                    $product_image->saveAs($url.$f_product_image);
                    $this->createThumb($url.$f_product_image, $thumb.'thumb_' . $f_product_image);
                }

                $this->redirect(array('submitted'));
            }
        }

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

问题在于您当前的定义

在模型中,指定更新场景下的安全属性

array('product_image, ..., product_gallery_6',  ...  'on'=>'update', 'safe'=>true)
$model = new MyActiveRecord('update');
因此,在控制器中,需要设置场景

array('product_image, ..., product_gallery_6',  ...  'on'=>'update', 'safe'=>true)
$model = new MyActiveRecord('update');
由于您使用的函数可能无法控制,因此可以显式设置:

$model->scenario = 'update';

请注意,您的问题可能在其他地方,具体取决于loadModule()的操作,因为ceratin ActiveRecord场景是自动加载的。请参阅链接页面中的“CActiveRecord场景”部分。

这就是错误:未能设置不安全属性(产品图片)