I am trying to open file from DB using Contoller code from this Wiki.
In my controller I have code:
public function displayCv()
{
$model=$this->loadModel();
header('Content-Type: '.$model->cv_file_type);
echo $model->cv_file_content; // echo data from blob
}
The function name should start with action, in order to be an action of the controller.
Try:
public function actionDisplayCv()
{
$model=$this->loadModel();
header('Content-Type: '.$model->cv_file_type);
echo $model->cv_file_content; // echo data from blob
}
And then calling a url generated bt CHtml::link(‘download curriculum’, array(‘displayCv’, ‘id’=>$model->primaryKey));
public function actionDisplayCv()
{
$model=$this->loadModel();
header('Content-Type: '.$model->cv_file_type);
echo $model->cv_file_content; // echo data from blob
}
Missing argument 1 for CandidateController::loadModel()
What seems to be obvious, because loadModel() takes argument.
When I change code to:
public function actionDisplayCv()
{
///////////////////// $id as argument /////////
$model=$this->loadModel($id);
header('Content-Type: '.$model->cv_file_type);
echo $model->cv_file_content; // echo data from blob
}
I get CHttpException on the view:
[size="5"]Error 404[/size]
The requested page does not exist.
That means that this function loadModel():
public function loadModel($id)
{
$model=Candidate::model()->findByPk((int)$id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
Throws an exception - it looks like ‘id’ is not being pased from view to controller… Any suggestions?
Note: you have to call [color="#008000"]$model=$this->loadModel($_GET[‘id’]);[/color]
Not[color="#FF0000"] $model=$this->loadModel();[/color] - like previously in the Wiki - NOW CORRECTED.
Nor [color="#0000FF"]$model=$this->loadModel($id);[/color]
Hope it [color="#FF0000"]h[/color][color="#006400"]e[/color][color="#0000FF"]l[/color][color="#FFA500"]p[/color][color="#9932CC"]s[/color] someone.
Now [color="#FF0000"]W[/color][color="#006400"]i[/color][color="#0000FF"]k[/color][color="#FFA500"]i[/color] contains full upload file to DB and open/retrieve it from DB tutorial.