Guest User

Untitled

a guest
Mar 12th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. public function add()
  2. {
  3. $administrador = $this->Administradors->newEntity();
  4. if ($this->request->is('post')) {
  5.  
  6. $this->loadModel('Personas');
  7. $persona = $this->Personas->newEntity();
  8. $persona->rut = $this->request->data['Personas']['rut'];
  9. $persona->sexo = $this->request->data['Personas']['sexo'];
  10. $persona->nombre = $this->request->data['Personas']['nombre'];
  11. $persona->apellido_paterno = $this->request->data['Personas']['apellido_paterno'];
  12. $persona->apellido_materno = $this->request->data['Personas']['apellido_materno'];
  13. $persona->direccion = $this->request->data['Personas']['direccion'];
  14. $persona->telefono_fijo = $this->request->data['Personas']['telefono_fijo'];
  15. $persona->telefono_movil = $this->request->data['Personas']['telefono_movil'];
  16. $persona->fecha_nacimiento = $this->request->data['Personas']['fecha_nacimiento'];
  17. $persona->email = $this->request->data['Personas']['email'];
  18. $persona->comuna_id = $this->request->data['Personas']['comuna_id'];
  19.  
  20. if(!$this->Personas->save($persona)){
  21.  
  22. $this->Flash->error('The administrador could not be saved. Please, try again.');
  23. }
  24.  
  25.  
  26.  
  27. $administrador = $this->Administradors->newEntity();
  28.  
  29. $administrador->persona_id = $persona->id;
  30.  
  31. if(!$this->Administradors->save($administrador)){
  32.  
  33. $this->Flash->error('The administrador could not be saved. Please, try again.');
  34. }
  35.  
  36. $this->loadModel('Users');
  37. $user = $this->Users->newEntity();
  38. $user->username = $persona->email;
  39. $user->password = $this->rand_passwd(6);
  40. $user->estado = true;
  41. $user->persona_id = $persona->id;
  42. $user->role_id = ADMIN;
  43.  
  44. if($this->Users->save($user)){
  45.  
  46. $this->Flash->success('The administrador has been saved.');
  47.  
  48. return $this->redirect(['action' => 'index']);
  49.  
  50. }else{
  51. $this->Flash->error('The administrador could not be saved. Please, try again.');
  52. }
  53.  
  54. }
  55. $personas = $this->Administradors->Personas->find('list', ['limit' => 200]);
  56. $this->set(compact('administrador', 'personas'));
  57. $this->set('_serialize', ['administrador']);
  58.  
  59. $this->loadModel('Regions');
  60. $comunas = $this->Regions->Comunas->find('list', ['limit' => 200]);
  61. $this->set(compact('comuna', 'comunas'));
  62. $this->set('_serialize', ['comuna']);
  63. }
  64.  
  65. <?php
  66. $this->Flash->error(__('Your error message'), ['key' => 'error']);
  67. ?>
  68.  
  69. <?= $this->Flash->render('error'); ?>
  70.  
  71. <?php
  72. if (!isset($params['escape']) || $params['escape'] !== false) {
  73. $message = h($message);
  74. }
  75. ?>
  76. <div class="alert alert-success" onclick="this.classList.add('hidden')"><?= $message ?></div>
Add Comment
Please, Sign In to add comment