Ver Mensaje Individual
  #11 (permalink)  
Antiguo 14/04/2011, 14:17
Avatar de masterpuppet
masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 3 meses
Puntos: 845
Respuesta: Recibir parámetros por GET en MVC

Los FW's lo manejan a través de helpers, no son mas que clases encargadas de hacer tareas comúnes a los controllers, para mantener el DRY, un ejemplo(siguiendo tus anteriores threads):

Código PHP:
Ver original
  1. class DaoHelper
  2. {
  3.     ...
  4.     public function findRecordOrException($id, $dao)
  5.     {
  6.         if(is_string($dao)) {
  7.             $dao = new $dao();
  8.         }
  9.         if( ! $dao instanceof IDao) {
  10.             throw new InvalidArgumentException(/***/);
  11.         }
  12.         $record = $dao->find($id);
  13.         if(false === $record) {
  14.             throw new RecordNotFoundException();
  15.         }
  16.         return $record;
  17.     }
  18.  
  19.     public function findRecordOrRedirect($id, $dao)
  20.     {/***/}
  21.  
  22.     public function findRecordOrLog($id, $dao)
  23.     {/***/}
  24.     ...
  25. }

luego en el controller
Código PHP:
Ver original
  1. public function updateAction()
  2. {
  3.     $id = $this->getQuery('id');
  4.     $helper = new DaoHelper();
  5.     try {
  6.         $record = $helper->findRecordOrException((int)$id, 'UserDao');
  7.     } catch(InvalidArgumentException $e) {
  8.         //handle Exception
  9.     } catch(RecordNotFoundException $e) {
  10.         //handle Exception
  11.     }
  12. }

Saludos.
__________________
http://es.phptherightway.com/
thats us riders :)