رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
خطای مربوط به تصویر محصول در هنگام غیرفعال سازی محصول
#1
سلام و درود
من دو تا اکشن دارم که یکی برای غیرفعال سازی محصول هست و یکی هم برای ایجاد محصول جدید
وقتی میخوام یک محصول رو غیرفعال کنم خطایی مربوط به تصویر میاد که میگه تصویر نمیتونه خالی باشه
در اصل وقتی ولیدیشن مربوط به تصویر رو برمیدارم مشکلی بوجود نمیاد!
کد هر اکشن و خطا رو میگذارم ببینید :

این کد اکشن غیرفعال کردن :
public function actionDisable($id)
    {
        $model = $this->loadModel($id);
        $model->status = 0;
        if ($model->save()) {
            Yii::app()->request->redirect(Yii::app()->request->urlReferrer);
        }
        Utils::debug($model);

    }

این کد ایجاد محصول :
public function actionNew()
    {
        $model = new Products;
        $this->render('new', compact('model'));
        if (isset($_POST['Products'])) {
            // get instance of uploaded file for $model->image
            $img = CUploadedFile::getInstance($model, 'imgFile');
            // create uploaded image path
            $path = Yii::app()->basePath . '/../images/' . $img->name;
            $img->saveAs($path);
            $model->image = $img->name;
            $model->attributes = $_POST['Products'];
            if ($model->save()) {
                $this->redirect('admin/products/index');
            }
        }
    }

اینم ولیدیشن هایی هست که باید روی هر فیلد انجام بشه :
public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('code, title, description, price', 'required'),
			array('price, status', 'numerical', 'integerOnly'=>true),
			array('code, title', 'length', 'max'=>255),
			// imgFile is for file of image and the address of image will store in 'image' field.
            array('imgFile','file','types'=>'jpg, gif, png', 'safe' => false),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, code, title, description, price, status', 'safe', 'on'=>'search'),
		);
	}

توی تصویر با خط قرمز مشخص شده که مدل چه خطایی رو در بر داره..
تصویر در ضمیمه.


فایل‌های پیوست تصاویر بندانگشتی
   
! WORK HARD
پاسخ
تشکر شده توسط:




کاربران در حال بازدید این موضوع: 1 مهمان