El código seguro para get por un param id es:
// 1. preguntar si viene id
if (!isset($this->params['id']))
{
header('Content-type: application/json');
return $this->renderString( json_encode(array('message'=>'id is required', 'status'=>'error', 'errors'=>array())) );
}
// 2. hacer el get
$ins = TheClass::get( $this->params['id'] );
// 3. ver si se obtuvo una instancia
if ($ins == null)
{
header('Content-type: application/json');
return $this->renderString( json_encode(array('message'=>'the instance doesnt exists', 'status'=>'error', 'errors'=>array())) );
}
Esto se debe hacer cada vez que se quiere hacer get(id). getCheck haría esta
lógica y devolvería esos 2 errores mediante códigos estándar. El
controller luego puede decidir si hacer render de una view, redirect o devolver
un JSON (como en este caso).
Original issue reported on code.google.com by pablo.swp@gmail.com on 3 Sep 2013 at 3:39
Original issue reported on code.google.com by
pablo.swp@gmail.com
on 3 Sep 2013 at 3:39