How do I get a saved record from the Cakephp database

Asked

Viewed 599 times

1

Good evening, how do I get a specific field on my table. I wanted to take this field and receive it in a variable and show in the view. Thank you!!

  • 1

    Explain a little better, how is the table, which field you want to pick up, how is your model, your controller and your view. Use the question’s [Edit] link to add this information.

  • table Sales with the value field, I want to take it and put in a variable called $total and send to the view

  • Salescontroller, Sale, managed everything beautiful

1 answer

3

Is the view relative to the same table model or different? If it is the same:

 $total = $sales['Sale']['valor'];

If it’s different, in your view controller, it’s:

 public function view(){
         $this->loadModel('Sale');
            $sales = $this->Sale->find('list', array('fields' => array('Sale.valor')));
            $this->set('valor', $valor);

So in view.ctp:

 $total = $valor['Sale']['valor'];

Browser other questions tagged

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