Hello again.
I’m having a problem with a beforeSave function that does not seem to even execute. I want to save three PDF files into the database and here is the code:
AVAIABLE COLUMNS:
* @property string $NamePDF1
* @property string $PDF1
* @property string $NamePDF2
* @property string $PDF2
* @property string $NamePDF3
* @property string $PDF3
VARIABLES FOR UPLOAD:
public $uploadFile1;
public $uploadFile2;
public $uploadFile3;
RULES:
array('uploadFile1', 'file', 'types'=>'pdf', 'allowEmpty' => true),
array('uploadFile2', 'file', 'types'=>'pdf', 'allowEmpty' => true),
array('uploadFile3', 'file', 'types'=>'pdf', 'allowEmpty' => true),
BEFORESAVE FUNCTION:
public function beforeSave()
{
if($file=CUploadedFile::getInstance($this,'uploadFile1'))
{
$this->NamePDF1=$file->name;
$this->PDF1=file_get_contents($file->tempName);
}
if($file=CUploadedFile::getInstance($this,'uploadFile2'))
{
$this->NamePDF2=$file->name;
$this->PDF2=file_get_contents($file->tempName);
}
if($file=CUploadedFile::getInstance($this,'uploadFile3'))
{
$this->NamePDF3=$file->name;
$this->PDF3=file_get_contents($file->tempName);
}
return parent::beforeSave();
}
FORM VIEW:
<div class="row">
<?php echo $form->labelEx($model,'uploadFile1'); ?>
<?php echo $form->fileField($model,'uploadFile1'); ?>
<?php echo $form->error($model,'uploadFile1'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'uploadFile2'); ?>
<?php echo $form->fileField($model,'uploadFile2'); ?>
<?php echo $form->error($model,'uploadFile2'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'uploadFile3'); ?>
<?php echo $form->fileField($model,'uploadFile3'); ?>
<?php echo $form->error($model,'uploadFile3'); ?>
</div>
I do not know what I am missing here. The only thing I did is that I write the avaiable columns by hand. Anywhere else that I should add code? This should work…