fbpx

funcion generica en controlador

En el archivo app_controller.php se escriben las funciones que heredan todos los controladores.

class AppController extends Controller {

var $components = array (‘RequestHandler’);
var $helpers = array( ‘Html’, ‘Javascript’ );

function listar() {

$total = $this->{$this->modelClass}->findCount();
$this->set(‘total’, $total );

if ( $this->params[‘form’] && $total > $this->params[‘form’][‘limit’] ){
$dir = $this->params[‘form’][‘dir’];
$limit = $this->params[‘form’][‘limit’];
$sort = $this->params[‘form’][‘sort’];
$start = $this->params[‘form’][‘start’];
$page = (integer) ($start / $limit) + 1;
$this->set( ‘respuesta’, $this->{$this->modelClass}->findAll( null, null, $this->modelClass.’.’.$sort.’ ‘.$dir, $limit, $page ) );
} else
$this->set( ‘respuesta’, $this->{$this->modelClass}->findAll() );

}

}

Don’t Stop Here

More To Explore