Advertisement
Guest User

Untitled

a guest
May 28th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.95 KB | None | 0 0
  1. <?php
  2. class DemandantesController extends AppController {
  3.  
  4.     var $name = 'Demandantes';
  5.  
  6.     function index() {
  7.         $this->Demandante->recursive = 0;
  8.         $this->set('demandantes', $this->paginate());
  9.     }
  10.  
  11.     /*function view($id = null) {
  12.         if (!$id) {
  13.             $this->Session->setFlash(sprintf(__('Invalid %s', true), 'demandante'));
  14.             $this->redirect(array('action' => 'index'));
  15.         }
  16.         $this->set('demandante', $this->Demandante->read(null, $id));
  17.     }*/
  18.     function view($cedula = null) {
  19.         $juzgado = $this->loadModel('Juzgado', $this->Demandante->find('first', array('cedula'=>$cedula)));
  20.         $this->set('juzgado', $juzgado);
  21.         if (!$cedula) {
  22.             $this->Session->setFlash(sprintf(__('Invalid %s', true), 'demandante'));
  23.             $this->redirect(array('action' => 'index'));
  24.         }
  25.         //$this->set('demandante', $this->Demandante->read(null, $id));
  26.         $demandante = $this->set('demandante', $this->Demandante->find('first', array('conditions' => array('Demandante.cedula'=>$cedula))));
  27.         var_dump($this->demandante);
  28.         $demandado = $this->loadModel('Demandado', $demandante['Proceso']['demandado_id']);
  29.         $this->set('demandado', $demandado);
  30.     }
  31.  
  32.     function add() {
  33.         if (!empty($this->data)) {
  34.             $this->Demandante->create();
  35.             $this->loadModel('Usuario');
  36.             $this->Usuario->create();
  37.             if ($this->Demandante->save($this->data) && $this->Usuario->save(array(
  38.                     'id'=>$this->data['Demandante']['cedula'],
  39.                     'username'=>$this->data['Demandante']['cedula'],
  40.                     'password'=>$this->Auth->password($this->data['Demandante']['cedula']),
  41.                     'grupo_id'=>'3'
  42.                     )
  43.                 )
  44.             ) {
  45.                 $this->Session->setFlash(sprintf(__('The %s has been saved', true), 'demandante'));
  46.                 $this->redirect(array('action' => 'index'));
  47.             } else {
  48.                 $this->Session->setFlash(sprintf(__('The %s could not be saved. Please, try again.', true), 'demandante'));
  49.             }
  50.         }
  51.     }
  52.  
  53.     function edit($id = null) {
  54.         if (!$id && empty($this->data)) {
  55.             $this->Session->setFlash(sprintf(__('Invalid %s', true), 'demandante'));
  56.             $this->redirect(array('action' => 'index'));
  57.         }
  58.         if (!empty($this->data)) {
  59.             if ($this->Demandante->save($this->data)) {
  60.                 $this->Session->setFlash(sprintf(__('The %s has been saved', true), 'demandante'));
  61.                 $this->redirect(array('action' => 'index'));
  62.             } else {
  63.                 $this->Session->setFlash(sprintf(__('The %s could not be saved. Please, try again.', true), 'demandante'));
  64.             }
  65.         }
  66.         if (empty($this->data)) {
  67.             $this->data = $this->Demandante->read(null, $id);
  68.         }
  69.     }
  70.  
  71.     function delete($id = null) {
  72.         if (!$id) {
  73.             $this->Session->setFlash(sprintf(__('Invalid id for %s', true), 'demandante'));
  74.             $this->redirect(array('action'=>'index'));
  75.         }
  76.         if ($this->Demandante->delete($id)) {
  77.             $this->Session->setFlash(sprintf(__('%s deleted', true), 'Demandante'));
  78.             $this->redirect(array('action'=>'index'));
  79.         }
  80.         $this->Session->setFlash(sprintf(__('%s was not deleted', true), 'Demandante'));
  81.         $this->redirect(array('action' => 'index'));
  82.     }
  83. }
  84. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement