Friday, October 1, 2010

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

Hi psybear83,

Completing waht cricket said..

After using $this->Model->set(); you need to use $this->Model->save();
if you want to save the value to DB.

In your case this should work:
$this->Contract->set('date', '2010-11-11');
$this->Contract->save();

Ref: http://book.cakephp.org/view/1031/Saving-Your-Data

Hope this helps.
LipeDjow

On 30 set, 14:22, cricket <zijn.digi...@gmail.com> wrote:
> On Thu, Sep 30, 2010 at 5:46 AM, psybear83 <psybea...@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: