hi guys
i have read this article yiiframework.com/wiki/2
and i have done everything step by step .
but it’s not working !
this is the model which i just copy and then paste :
class Item extends CActiveRecord
{
public $image;
// ... other attributes
public function rules()
{
return array(
array('image', 'file', 'types'=>'jpg, gif, png'),
);
}
}
my view is exactly the same as the article :
$form = $this->beginWidget(
'CActiveForm',
array(
'id' => 'upload-form',
'enableAjaxValidation' => false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)
);
// ...
echo $form->labelEx($model, 'image');
echo $form->fileField($model, 'image');
echo $form->error($model, 'image');
// ...
echo CHtml::submitButton('Submit');
$this->endWidget();
and my controller is :
class ItemController extends CController
{
public function actionCreate()
{
$model=new Item;
if(isset($_POST['Item']))
{
$model->attributes=$_POST['Item'];
$model->image=CUploadedFile::getInstance($model,'image');
if($model->save())
{
$model->image->saveAs(dirname(__FILE__).'/a.txt');
// redirect to success page
}
}
$this->render('create', array('model'=>$model));
}
}
when i choose an image(jpg , png , or something else) the controller doesn’t see my file , i mean isset($_FILES[‘Item’]) is false … i know it’s false because i check it with var_dump hundreds of times :
public function actionCreate()
{
$model=new Item;
var_dump(isset($_POST['Item']));
...
i also test var_dump(isset($_FILES[‘Item’])) which was false either .
for every kinds of file(except plain txt file) $_POST[‘Item’]) remains empty.
i checked my request using firebug network panel(both firefox and chrome) and the request had the file .
what do you think ?