Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function add()
- {
- $administrador = $this->Administradors->newEntity();
- if ($this->request->is('post')) {
- $this->loadModel('Personas');
- $persona = $this->Personas->newEntity();
- $persona->rut = $this->request->data['Personas']['rut'];
- $persona->sexo = $this->request->data['Personas']['sexo'];
- $persona->nombre = $this->request->data['Personas']['nombre'];
- $persona->apellido_paterno = $this->request->data['Personas']['apellido_paterno'];
- $persona->apellido_materno = $this->request->data['Personas']['apellido_materno'];
- $persona->direccion = $this->request->data['Personas']['direccion'];
- $persona->telefono_fijo = $this->request->data['Personas']['telefono_fijo'];
- $persona->telefono_movil = $this->request->data['Personas']['telefono_movil'];
- $persona->fecha_nacimiento = $this->request->data['Personas']['fecha_nacimiento'];
- $persona->email = $this->request->data['Personas']['email'];
- $persona->comuna_id = $this->request->data['Personas']['comuna_id'];
- if(!$this->Personas->save($persona)){
- $this->Flash->error('The administrador could not be saved. Please, try again.');
- }
- $administrador = $this->Administradors->newEntity();
- $administrador->persona_id = $persona->id;
- if(!$this->Administradors->save($administrador)){
- $this->Flash->error('The administrador could not be saved. Please, try again.');
- }
- $this->loadModel('Users');
- $user = $this->Users->newEntity();
- $user->username = $persona->email;
- $user->password = $this->rand_passwd(6);
- $user->estado = true;
- $user->persona_id = $persona->id;
- $user->role_id = ADMIN;
- if($this->Users->save($user)){
- $this->Flash->success('The administrador has been saved.');
- return $this->redirect(['action' => 'index']);
- }else{
- $this->Flash->error('The administrador could not be saved. Please, try again.');
- }
- }
- $personas = $this->Administradors->Personas->find('list', ['limit' => 200]);
- $this->set(compact('administrador', 'personas'));
- $this->set('_serialize', ['administrador']);
- $this->loadModel('Regions');
- $comunas = $this->Regions->Comunas->find('list', ['limit' => 200]);
- $this->set(compact('comuna', 'comunas'));
- $this->set('_serialize', ['comuna']);
- }
- <?php
- $this->Flash->error(__('Your error message'), ['key' => 'error']);
- ?>
- <?= $this->Flash->render('error'); ?>
- <?php
- if (!isset($params['escape']) || $params['escape'] !== false) {
- $message = h($message);
- }
- ?>
- <div class="alert alert-success" onclick="this.classList.add('hidden')"><?= $message ?></div>
Add Comment
Please, Sign In to add comment