¿Hay algún problema de automagic en zend framework como la fecha de creación y modificación en la tabla mysql?

In cakephp there can be two columns for mysql tables one is "created" and other is "modified".

So when a post is created or updated the two columns are automatically updated.

Is there any issue like that for zend framework ?

Any automagic issue ?

preguntado el 27 de agosto de 11 a las 17:08

No, there isn't. That's what there is. None. -

1 Respuestas

Zend doesn't do any magic. Though you can ask MySQL to do it ;) with the help of TIMESTAMP and TRIGGERS .

Here is a few code that may help .

SET NAMES utf8;
SET foreign_key_checks = 0;
SET time_zone = 'SYSTEM';
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';

DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

INSERT INTO `test` (`id`, `name`, `updated`, `created`) VALUES
(1, 'test', '2011-08-28 13:47:21',  '0000-00-00 00:00:00'),
(2, 'hello',    '0000-00-00 00:00:00',  '0000-00-00 00:00:00'),
(3, 'hari', '2011-08-28 13:48:48',  '0000-00-00 00:00:00'),
(4, 'test', '2011-08-28 13:50:12',  '2011-08-23 08:19:47');

DELIMITER ;;

CREATE TRIGGER `on-insert` BEFORE INSERT ON `test` FOR EACH ROW
SET NEW.created = UTC_TIMESTAMP;;

DELIMITER ;

Or you can also do without trigger like either on inserting or updating pass the NOW() with the data and make either update or created timestamp DEFAULT or UPDATE . As you cannot do two things ( only for update or insert ). The code above is an inspiration from some of the comments in MySQL

Respondido 28 ago 11, 12:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.