Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Saving File From Parent Model

$
0
0
Hi there,

I've an unusual situation.
My parent model (Booking) has a related model (Bookingdocument) to manage received/sent documents. For received documents, my child model has an upload form and this works fine. Documents to be sent out are created and phisically saved by my parent model as pdf files. I need to save a Bookingdocument model for each of these pdf files as they are created and here I'm stuck.
My Booking model code looks like this:
$fName = $this->pdfCreateDocument($rDoc->documenttype->template, $rDoc->documenttype->filename, $this->getBookingFolder());
if ($this->pdfSendDocument($fName, $rDoc->documenttype->template))
{
	$newBDoc = new Bookingdocument;
	$newBDoc->booking_id = $this->id;
	$newBDoc->bookingpax_id = 0;
	$newBDoc->offertypedocument_id = $rDoc->documenttype_id;
	$newBDoc->docdate = date('Y-m-d H:i:s');
	$newBDoc->document_filename = $fName;
								
	$docFile = CUploadedFile::getInstance($newBDoc,'document_filename');
	if (is_object($docFile) && get_class($docFile)==='CUploadedFile')
					$newBDoc->document_filename = $docFile;
				
	$bookFolder = $this->getBookingFolder();
	if (is_object($newBDoc->document_filename))
	 				$newBDoc->document_filename->saveAs($bookFolder.DIRECTORY_SEPARATOR.$newBDoc->document_filename->name);
								
	var_dump('Saving object type '.get_class($docFile));
	$tmpResult = $newBDoc->save();
	if($tmpResult)
		var_dump('Saved');
}

I've copied lines from my BookingdocumentController here but this is obviously wrong: I'm not uploading any file, I'm using a file that has been already created, saved (by pdfCreateDocument) and sent (by pdfSendDocument).
I shouldn't get an instance of an uploaded file, because my file is already existing.
And I shouldn't save file, right?
Moreover, get_class($docFile) above returns class 'Booking', not what I thought.
But I have no idea how to face this issue.
Anyone pointing me to the right direction?

TIA,
rash*

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>