Taking the last position in the bank

1

I need to get the last row of a column using CakePHP.

I'm trying like this:

$idAtual = $this->Albun->find('all', array('fields' => 'codigo'));

Only he is returning all lines. How to get only the last?

    
asked by anonymous 25.03.2014 / 20:48

2 answers

2

You have to add descending order and change all to first

 $idAtual = $this->Albun->find('first', array('fields' => 'codigo', 'order' => array('codigo DESC')));

More infos:

BookCakephp

    
26.03.2014 / 01:01
0

could do something like this

currently inserted case

echo $this->Albun->getInsertID();

Insert the code here by putting the last one inserted in the base for the table

echo $this->Albun->getLastInsertID();

    
26.03.2014 / 14:57