Been working on this for a day, read all the other posts on this topic but couldn’t find the solution.
Did a var_dump and $_POST[ModelName] didn’t have anything listed for the imagefile.
ERROR:
Property "ModelName.imagefile" is not defined.
STACK:
C:\xampp\framework\db\ar\CActiveRecord.php(126)
public function __set($name,$value)
{
if($this->setAttribute($name,$value)===false)
{
if(isset($this->getMetaData()->relations[$name]))
$this->_related[$name]=$value;
else
***** parent::__set($name,$value); ***** THIS IS HIGHLIGHTED
}
}
FROM CONTROLLER
if(isset($_POST['ModelName']))
{
**** $model->attributes=$_POST['ModelName'];**** THIS IS HIGHLIGHTED
if($model->validate()){
$model->imagefile=CUploadedFile::getInstance($model,'imagefile');
$model->imagefile->saveAs('files/'.$model->imagefile);
....
This is the only reference in my model:
array('imagefile', 'file', 'allowEmpty'=>true ),
_form
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'upload-form',
'enableAjaxValidation'=>false,
'htmlOptions'=>array('enctype'=>'multipart/form-data'),
)); ?>
<?php echo $form->labelEx($model,'imagefile'); ?>
<?php echo $form->fileField($model,'imagefile'); ?>
<?php echo $form->error($model,'imagefile'); ?>