Witam,
Mam pewien problem. Przesyłam z formularza pewne dane. Akcja dodająca te elementy do bazy wygląda tak:
public function actionUpdate($id)
{
$model=$this->loadModel($id);
$this->performAjaxValidation($model);
if(isset($_POST['Product']))
{
$old_image = $model->image;
$old_image2 = $model->image2;
$old_image3 = $model->image3;
$model->attributes=$_POST['Product'];
if($model->save())
{
...
}
$this->redirect(array('view','id'=>$model->id));
}
}
}
Z formularza przesyłam dwa pola o nazwach ‘image2’ i ‘image3’ + jedno testowe ‘test’. Debugując aplikację, zdołałem zauważyć że:
-
formularz POST jest przesylany poprawnie, wraz ze wszystkimi wartościami
-
$model->attributes=$_POST[‘Product’]; to przypisanie nie działa. Żadne z tych trzech dodatkowych pól nie zostaje poprawnie przypisane.
-
w model->_attributes pojawia się pole ‘test’, jednak jak już wspomniałem przypisanie nie działa prawidłowo.
-
pola i’image2’ i ‘image3’ w modelu w ogóle nie istnieją.
Reguły modelu wyglądają następująco:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('name', 'required'),
array('promotion', 'numerical', 'integerOnly'=>true),
array('archived', 'numerical', 'integerOnly'=>true),
array('category_id', 'length', 'max'=>10),
array('sort_order', 'length', 'max'=>11),
array('name', 'length', 'max'=>128),
array('image', 'length', 'max'=>64),
array('image2', 'length', 'max'=>64),
array('image3', 'length', 'max'=>64),
array('test', 'length', 'max'=>64),
array('description_short_pl, description_short_en, description_long_pl, description_long_en', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, category_id, name, image, image2, image3, promotion, archived, description_short_pl, description_short_en, description_long_pl, description_long_en', 'safe', 'on'=>'search'),
);
}
Oczywiście pola w tabeli istnieją i mają się dobrze. Bardzo proszę o pomoc, konkretnie: dlaczego pola image2 i image3 nie istnieją w atrybutach modelu i dlaczego pole ‘test’ nie zostaje poprawnie przypisane. Pozostałe elementy formularza działają bezbłędnie.