· 8 years ago · May 11, 2018, 04:14 PM
1add.ctp
2
3<h1>Agregar Persona <h1>
4<?php
5 echo $this->Form->create('Person');
6 echo $this->Form->input('name', array ('label' => 'Nombre'));
7 echo $this->Form->input('lastname', array ('label' => 'Apellido Paterno'));
8 echo $this->Form->input('longlastname', array('label' => 'Apellido Materno'));
9 echo $this->Form->input('sex', array('label' => 'Sexo',
10 'options' => array ('Mujer','Hombre'),
11 'empty' => 'Seleccione su sexo'));
12 echo $this->Form->input('born', array('label'=>'Fecha de Nacimiento','minYear'=>1950));
13 echo $this->Form->input('blood', array('label'=>'Tipo de Sangre'));
14 echo $this->Form->input('curp', array('label'=>'Curp'));
15 echo $this->Form->input('phone', array('label'=>'Telefono'));
16 echo $this->Form->input('state_id', array('label'=>'Estado de Nacimiento'));
17 echo $this->Form->end('Guardar');
18
19?>
20
21controller.php
22
23 public function add() {
24
25 if ($this->request->is('post')) {
26 if ($this->Person->save($this->request->data)) {
27 $this->Session->setFlash('Se ha dado de alta esta persona');
28 $this->redirect(array('action' => 'index'));
29 }
30 else {
31 $this->Session->setFlash('No se pudo dar de alta a esta persona, intentelo mas tarde.');
32 }
33 }
34 $estados = $this->Person->State->find('list',array ('fields'=>'State.state','State.town'));
35 $this->set('states', $estados);
36 }
37
38
39
40TABLA
41
42CREATE TABLE IF NOT EXISTS `states` (
43 `id` int(11) NOT NULL AUTO_INCREMENT,
44 `state` varchar(25) DEFAULT NULL,
45 `town` varchar(50) DEFAULT NULL,
46 `municipality` varchar(40) DEFAULT NULL,
47 PRIMARY KEY (`id`)
48) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5443 ;
49
50CREATE TABLE IF NOT EXISTS `people` (
51 `id` int(11) NOT NULL AUTO_INCREMENT,
52 `name` varchar(45) DEFAULT NULL,
53 `lastname` varchar(35) DEFAULT NULL,
54 `longlastname` varchar(35) DEFAULT NULL,
55 `sex` tinyint(1) DEFAULT NULL,
56 `born` date DEFAULT NULL,
57 `blood` varchar(10) DEFAULT NULL,
58 `curp` varchar(18) DEFAULT NULL,
59 `phone` varchar(15) DEFAULT NULL,
60 `state_id` int(11) NOT NULL,
61 PRIMARY KEY (`id`,`state_id`)
62) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
63
64--
65-- Volcar la base de datos para la tabla `people`
66--
67
68INSERT INTO `people` (`id`, `name`, `lastname`, `longlastname`, `sex`, `born`, `blood`, `curp`, `phone`, `state_id`) VALUES
69(1, 'javier', 'carmona', 'Lopez', 1, '2023-12-23', 'roja', '000lkdfldsk', '2411126341', 15),
70(2, '', '', '', 0, '2011-12-23', '', '', '', 76),
71(3, 'fkdj', 'kfjd', 'jkdf', 1, '2011-12-27', 'osidfj', 'oxdvj', '23094', 8),
72(4, '', '', '', 0, '2011-12-27', 'xc', '', '', 4223);