I’m using a postgresql 9.1 database, where a pdf file is stored in a large object field (oid). Now I want to show the pdf-file in a link where the user can click for watching it. I’ve searched a long time for doing this with Yii but without success.
I wondered if Yii bringing such stuff with it?
Or do I have to use the php [font="Courier New"]pg_lo_open[/font] and [font="Courier New"]pg_lo_read[/font] function itself? If so how can I get the database connection ressource needed by this functions (which normally will be returned from pg_connect function)? I thought about
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('document', 'file', 'types' =>'pdf'),
);
}
In my controller I added the following action:
public function actionShowDoc($id) {
$model = Docs::model()->findByPk($id);
$this->renderPartial('_pdf_test', array('model'=>$doc));
}
And I added a new view file _pdf_test.php where I put:
yesterday I tried to use a bytea instead of a large object type in my database and doing the stuff which I wrote above. This works fine if I put the result of
$model->document
in the
stream_get_contents
function, reading here.
I can’t use this function for the large object type because in this case
$model->document
returns not a resource. At this time I use following workaround:
Yii::app()->db->createCommand("select lo_export(docs.document, '/tmp/$model->name.pdf') FROM docs where document=$model->document")->execute();
This statement saves the large object as pdf into /tmp folder. Then I load and display it in pdf viewer.