Thursday, September 30, 2010

Re: Manually set date field using a string "YYYY-MM-DD" does not work?

On Thu, Sep 30, 2010 at 5:46 AM, psybear83 <psybear83@gmail.com> wrote:
> Hi everybody
>
> Take a look at the following code:
>
>    $this->Contract->create($this-
>>getValidDataExcept(array('date'))); // Creates a nearly valid
> contract (only date is missing)
>    debug($this->Contract->field('date')); // (empty) - ok
>    debug($this->Contract->validates()); // 1
>    debug($this->Contract->field('date')); // 2009-09-24 - ok
>    $this->Contract->set('date', '2010-11-11');
>    debug($this->Contract->validates()); // 1
>    debug($this->Contract->field('date')); // 2009-09-24 - not ok!

Model::field() fetches the value from the DB. I think what you want to
be checking is Model::date var. What you've done is manually set the
Contract instance's $date var, then fetched the original value from
the DB (based on the current id).

> Can't I set a date field manually using a string?

Yes. There's nothing wrong with that part.

> And why does the model validate ...

Well, what does your $validation array look like?

> ... and simply ignore my seemingly wrong date input value?
> At least it should complain that date's value is not in a valid
> format, shouldn't it?

Why do you think the date format is wrong?

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: