Passing id to pdf printing with cakephp3 and tcpdf

Asked

Viewed 47 times

0

Personal I am generating reports in pdf and I am with the following problem, I need to set the id of the volunteer to print the pdf with the data of the volunteer, I tried as follows by the link:

view

<?= $this->Html->link(__('Imprimir'), ['action' => 'pdf_view2', $voluntario->id], ['class'=>'btn btn-info btn-xs']) ?>

it turns out that even though pdf printing obeys only the id I pass in the controller, so if I pass null, it comes null, if I pass the normal id as 2... comes the volunteer number 2... as I can pass the volunteer id to pdf_view?

controller

public function pdf_view2($schedule_id = null, $id = 2){        
      $this->viewBuilder()->layout('ajax');
      $this->set('title', 'My Great Title');
      $this->set('file_name', '2016-06' . '_June_CLM.pdf');
     $this->response->type('pdf');


  /*  $this->paginate = [
        'contain' => ['Oficinas']
    ];
    $voluntarios = $this->paginate($this->Voluntarios);
    

    $this->set(compact('voluntarios'));*/

    $voluntario = $this->Voluntarios->get($id, [
        'contain' => ['Oficinas']
    ]);

    

    $this->set('voluntario', $voluntario);

I need to take this id=2 and put so that it takes the volunteer id, how to do?

2 answers

0

Your method should look like this:

    public function pdf_view2($schedule_id = null, $id = null)
    {
      $this->viewBuilder()->layout('ajax');
      $this->set('title', 'My Great Title');
      $this->set('file_name', '2016-06' . '_June_CLM.pdf');
      $this->response->type('pdf');
      
      $voluntario = $this->Voluntarios->get($id, [
            'contain' => ['Oficinas'],
        ]);

        $this->set('voluntario', $voluntario);
    }

Here on this line:

<?= $this->Html->link(__('Imprimir'), ['action' => 'pdf_view2', $voluntario->id], ['class'=>'btn btn-info btn-xs']) ?>

You need to see what is being passed on $voluntario->id

This is what is going to the parameter. You need to see if you are loading the id correctly!

  • did not work... id goes in the right url ... but for some reason it does not return the volunteer in pdf... it only returns when I set it in the controller function

  • I updated the answer! Check the value of $voluntario->id.

  • get buddy. thanks a lot for the help, the value of the voluntario id was ok... a facebook guy advised me and I just switched places the $schedule_id = null and the $id = null kkk anyway thanks so much for helping me

-1

Change that line:

public function pdf_view2($schedule_id = null, $id = 2){

To:

public function pdf_view2($id = null, $schedule_id = null){

Its function receives the ID of your URL in the first parameter and not in the second.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.