Re: cake 1.2 forms: date fields left empty => null in database?

2008-12-18 Thread Sebastian Göttschkes

Hi,

thanks for your reply. The data field was set to null before. If I
update a dataset and assigning the null value to a the birthday field
(SET birthday=null) it works fine. So I added the following code to my
controller:
if(empty($this->data['Employee']['birthday']))
$this->data['Employee']['birthday'] = null;
This works fine, but I'm not sure if this is the proper way to do it?

Regards,
Sebastian

On 16 Dez., 15:13, Alexandru Ciobanu  wrote:
> Sebastian Göttschkes wrote:
> > Hi,
>
> > i got the following problem using cakePHP 1.2 RC3:
>
> > My Model 'Employee' has a attribute called 'birthday' (datatype:
> > DATE). In the add-view, I have the following code:
> > input('birthday',array('type'=>'text'));?>
> > If i left this field blank when adding an employee, this employee has
> > the birthday '-00-00' saved in the database. I would rather like
> > the birthday having the null-value, because -00-00 is no valid
> > birthday.
>
> Set the date field to NULL
> |ALTER TABLE `employees` CHANGE `birthday` `birthday` DATE NULL;
>
> IIRC
>
> HTH
> |
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: cake 1.2 forms: date fields left empty => null in database?

2008-12-17 Thread Adriano Varoli Piazza

On 16 dic, 11:44, Sebastian Göttschkes  wrote:
> Additionally, if I add a valid birthday, it is saved correctly. When
> editing the employee, I would like to get the birthday viewed in the
> format dd.mm.. How can I tell cake to view the birthday like this?

Ok, here's what I've done:

in the Obras edit / add view:

echo $html->div('input select',
$form->label('fecha_creacion', 'Fecha de Creación')
.
$form->day('fecha_creacion', null, array(), '---')
. ' - ' .
$form->month('fecha_creacion', null, array(), '---')
. ' - ' .
$form->year('fecha_creacion', 1600, date('Y'), null, array(),
false)
);

This shows the div, a label and three select fields for day, month,
year, separated by ' - ', with the year between 1600 and the current
year, and day and month optional (these are the dates in which works
of art were made, and sometimes the date is not exact).

On the Obras controller, before saving:

$tmp = $this->data['Obra']['fecha_creacion'];
$this->data['Obra']['fecha_creacion'] = $tmp['year']; // year is
mandatory
if ($tmp['month']) {
$this->data['Obra']['fecha_creacion'] .= '-' . $tmp['month'];
if ($tmp['day']) {  // only if they selected a month
$this->data['Obra']['fecha_creacion'] .= '-' . $tmp['day'];
}
}

HTH
--
Saludos
Adriano
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: cake 1.2 forms: date fields left empty => null in database?

2008-12-16 Thread Adriano Varoli Piazza

I am in the process of editing my views to get a similar effect. If
you can wait a couple hours, I'll be back with an explanation.

But, to whet your appetite: controlling for '-00-00' is not that
different from controlling for null, seems to me. '-00-00' is the
'null value' for a date field. I have the problem of dates that can be
full, or just years, or just years and months, so I can't use a date
field at all, and have to validate my dates otherwise.

Basically, to edit the date fields as you like, you have to process
them before saving in the edit method, filling up the $this->data
['yourdatefield'] with a valid date from what you got. For example:
in the view, you have three inputs type='text' name='dateday',
name='datemonth', name='dateyear'
in the action, get the date fields and process them saving each value
to your $this->data['yourdatefield'] as a full '-mm-dd' string.

Plus, you should also set the variable at the end of the edit action
doing the opposite action, so the dates to be modified should be
exploded and set to 'dateday', etc.

I hope I'm not making any mistaeks.

Cheers,

On 16 dic, 11:44, Sebastian Göttschkes  wrote:
> Hi,
>
> i got the following problem using cakePHP 1.2 RC3:
>
> My Model 'Employee' has a attribute called 'birthday' (datatype:
> DATE). In the add-view, I have the following code:
> input('birthday',array('type'=>'text'));?>
> If i left this field blank when adding an employee, this employee has
> the birthday '-00-00' saved in the database. I would rather like
> the birthday having the null-value, because -00-00 is no valid
> birthday.
>
> Additionally, if I add a valid birthday, it is saved correctly. When
> editing the employee, I would like to get the birthday viewed in the
> format dd.mm.. How can I tell cake to view the birthday like this?
>
> I hope you guys can help me.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



AW: cake 1.2 forms: date fields left empty => null in database?

2008-12-16 Thread Liebermann, Anja Carolin

 
Hi Sebastian,

You have to format the date for your view. If this is really woth the effort. I 
had a similar problem in a non cake Project.

I played around with 
$dateold = date("d.m.Y",strtotime($datefoo));
And
$datefoo= date("Y-m-d", strtotime("-$n day"));

Hope that helps. Be careful what format to validate!

Anja


-Ursprüngliche Nachricht-
Von: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] Im Auftrag 
von Sebastian Göttschkes
Gesendet: Dienstag, 16. Dezember 2008 14:45
An: CakePHP
Betreff: cake 1.2 forms: date fields left empty => null in database?


Hi,

i got the following problem using cakePHP 1.2 RC3:

My Model 'Employee' has a attribute called 'birthday' (datatype:
DATE). In the add-view, I have the following code:
input('birthday',array('type'=>'text'));?>
If i left this field blank when adding an employee, this employee has the 
birthday '-00-00' saved in the database. I would rather like the birthday 
having the null-value, because -00-00 is no valid birthday.

Additionally, if I add a valid birthday, it is saved correctly. When editing 
the employee, I would like to get the birthday viewed in the format dd.mm.. 
How can I tell cake to view the birthday like this?

I hope you guys can help me.

Thanks in advance,
Regards,
Sebastian


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: cake 1.2 forms: date fields left empty => null in database?

2008-12-16 Thread Alexandru Ciobanu

Sebastian Göttschkes wrote:
> Hi,
>
> i got the following problem using cakePHP 1.2 RC3:
>
> My Model 'Employee' has a attribute called 'birthday' (datatype:
> DATE). In the add-view, I have the following code:
> input('birthday',array('type'=>'text'));?>
> If i left this field blank when adding an employee, this employee has
> the birthday '-00-00' saved in the database. I would rather like
> the birthday having the null-value, because -00-00 is no valid
> birthday.
>
>   
Set the date field to NULL
|ALTER TABLE `employees` CHANGE `birthday` `birthday` DATE NULL;

IIRC

HTH
|

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



cake 1.2 forms: date fields left empty => null in database?

2008-12-16 Thread Sebastian Göttschkes

Hi,

i got the following problem using cakePHP 1.2 RC3:

My Model 'Employee' has a attribute called 'birthday' (datatype:
DATE). In the add-view, I have the following code:
input('birthday',array('type'=>'text'));?>
If i left this field blank when adding an employee, this employee has
the birthday '-00-00' saved in the database. I would rather like
the birthday having the null-value, because -00-00 is no valid
birthday.

Additionally, if I add a valid birthday, it is saved correctly. When
editing the employee, I would like to get the birthday viewed in the
format dd.mm.. How can I tell cake to view the birthday like this?

I hope you guys can help me.

Thanks in advance,
Regards,
Sebastian
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---