About creating variables

0

I use ZEND 2 and I'm in the controller. There I created an action to print a field (description) of a table (received). The issue is that when I connect the controller with the view nothing appears on the site. From what I've realized I have to set the value of the variable $saidarecibo by assigning it the value of the field of the table that calls description. How do I do this?

Below is my controller:

 public function imprecibosaidaAction() {

        $data_parametro = "";

        $saidarecibo = $descricao;

        $id = (int) $this->params()->fromRoute('id', 0);

        $saidarecibo = $this->getTable('Admin\Model\Saidarecibo')->get($id);

        //$this->view->saidarecibo = $saidarecibo;

        if ($id == 0) {
            throw new \Exception("Código obrigatório");
        }

         // Turn off the layout, i.e. only render the view script.
         $viewModel = new ViewModel();
         $viewModel->setTerminal(true);

        $view = new ViewModel(array(
            'saidarecibo' => $saidarecibo,
        ));

        //return $view;
        return $viewModel;

    }

Now follow the view I created, it should print only the table field:

<?php echo $this->saidarecibo; ?>

<a style="margin-top:10px;" href="javascript:self.print()">IMPRIMIR</a>
    
asked by anonymous 29.05.2014 / 17:13

2 answers

1

You have two things wrong. One in the controller: You are doing return of a different variable:

//estás a fazer return $viewModel; e devia ser 
return $view;

In action you also have the wrong use of the variable: Try using $saidarecibo instead of $this->saidarecibo In the action of the array of the object viewModel defines the name of the variable to use in the view.

    
06.08.2014 / 01:48
0

Correct when using output $viewModel->setTerminal(true); would be to assign the return variables in the same instance as follows:

$viewModel = new ViewModel();

$viewModel->setTerminal( true )->setVariables(array( 'saidarecibo' => $saidarecibo));

return $viewModel;
    
12.05.2015 / 18:39