Thursday, September 30, 2010

Re: CakePHP ignores notEmpty validation rule when the field's name is not a key in $data! (Bug or Feature?)

well, it is this way for "rapid development"
not for "most secure web application" :)

the second part is your job then
although i think my methods should find their way into the core
because they certainly help to achieve that.


On 30 Sep., 15:28, Joshua Muheim <psybea...@gmail.com> wrote:
> Thanks Euromark for your good hint. I certainly should read through
> your blogs in the near future...
>
> But do you know why CakePHP handles stuff this way? Looks very, very
> unintuitive to me. With Ruby on Rails I had much better experiences
> about stuff like this a few years ago (everything just seemed to work
> the way I expected it although I didn't have much experience with it
> then), and I'm sure today they even have progressed much farer...
>
> It seems a bit sad to me that CakePHP clearly doesn't seem to be able
> to come even close to the experience of RoR. Any yes, I know CakePHP
> isn't RoR, and yes, I could switch (well actually, I can't)... Just my
> 2 c€nts...
>
>
>
> On Thu, Sep 30, 2010 at 2:58 PM, euromark <dereurom...@googlemail.com> wrote:
> > actually it is NOT a bug
> > although many are not aware of that behavior :)
>
> > you need to make sure that the field is passed to the validation
> > otherwise it will be ignored
>
> > @seehttp://www.dereuromark.de/2010/09/21/saving-model-data-and-security/
>
> > On 30 Sep., 14:52, psybear83 <psybea...@gmail.com> wrote:
> >> Hi everybody
>
> >> I have baked the following very straight-forward model:
>
> >> class Post extends AppModel {
> >>         var $name = 'Post';
> >>         var $displayField = 'name';
> >>         var $validate = array(
> >>                 'name' => array(
> >>                         'notempty' => array(
> >>                                 'rule' => array('notempty')
> >>                         ),
> >>                 ),
> >>         );
>
> >> }
>
> >> It only needs a value for "name" to be saved.
>
> >> Now I've written the following 3 tests:
>
> >>   function testShouldNotBeValidWithEmptyName() {
> >>     $this->Post->create(array('name' => ''));
> >>     $this->assertFalse($this->Post->validates());
> >>   }
>
> >>   function testShouldNotBeValidWithoutName() {
> >>     $this->Post->create();
> >>     $this->assertFalse($this->Post->validates()); // Fails!
> >>   }
>
> >>   function testShouldNotBeValidWithNullName() {
> >>     $this->Post->create(array('name' => null));
> >>     $this->assertFalse($this->Post->validates());
> >>   }
>
> >> I expect all three of them to work, but the 2nd one fails! So why does
> >> it validate when there truly is no value for the "name" field? Is this
> >> really the way it should be, or is it a bug?
>
> >> I'm on version 1.3.4.
>
> >> Thanks for help
> >> Josh
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd 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 athttp://groups.google.com/group/cake-php?hl=en

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: