FAQ
I am trying to use the CakePHP 2.2.0-RC2 dynamic validation API to create a
new validation rule for a Model via a Controller.

First of all, is this possible at all?

So far when I try and run this in a controller:

$this->Campaign->validator()->add('advertiser_id', 'notEmpty', array(
'rule' => 'notEmpty',
'required' => true,
'message' => 'Assigning an advertiser is required'
));

When the model saves ($this->Campaign->save($this->request->data)), the
validation list does not appear to have the new validation rule in it. I
have traced out the validation set that the validator is using at save, and
it is using only the validation rules that were initially set in the model.

Any ideas? Am I going about this the wrong way? Am I missing anything?

The Book only show examples being done from within a Model class. Can we
not use this API from the Controller?

Any insight is appreciated.

AD

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


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

Search Discussions

  • JP at Jun 27, 2012 at 12:56 pm
    I got the same problem, but I made it globaly for captcha:

    // AppModel.php
    function addCaptchaValidation($result){
    $this->validator()
    ->add('Captcha', 'notEmpty', array(
    'rule' => 'notEmpty',
    'required' => true,
    'message' => 'form-validate-notEmpty',
    ))
    ->add('Captcha', 'captcha', array(
    'rule' => array('comparison', '==', $result),
    'message' => 'form-validate-captcha'
    ));
    }

    // in controller
    $this->MybuttContactForm->addCaptchaValidation($this->Captcha->result());


    Dne čtvrtek, 21. června 2012 2:23:33 UTC+2 Adam Duro napsal(a):
    I am trying to use the CakePHP 2.2.0-RC2 dynamic validation API to create
    a new validation rule for a Model via a Controller.

    First of all, is this possible at all?

    So far when I try and run this in a controller:

    $this->Campaign->validator()->add('advertiser_id', 'notEmpty', array(
    'rule' => 'notEmpty',
    'required' => true,
    'message' => 'Assigning an advertiser is required'
    ));

    When the model saves ($this->Campaign->save($this->request->data)), the
    validation list does not appear to have the new validation rule in it. I
    have traced out the validation set that the validator is using at save, and
    it is using only the validation rules that were initially set in the model.

    Any ideas? Am I going about this the wrong way? Am I missing anything?

    The Book only show examples being done from within a Model class. Can we
    not use this API from the Controller?

    Any insight is appreciated.

    AD
    --
    Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
    Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


    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
  • Majna at Jun 27, 2012 at 5:41 pm
    You can add validator form controller, added rules are not appended to
    Model::validate property.

    Try to debug :
    $this->Campaign->validator()->add('advertiser_id', 'notEmpty', array(
    'rule' => 'notEmpty',
    'required' => true,
    'message' => 'Assigning an advertiser is required'
    ));

    $this->Campaign->validates();
    debug($this->Campaign->validationErrors);
    On Thursday, June 21, 2012 2:23:33 AM UTC+2, Adam Duro wrote:

    I am trying to use the CakePHP 2.2.0-RC2 dynamic validation API to create
    a new validation rule for a Model via a Controller.

    First of all, is this possible at all?

    So far when I try and run this in a controller:

    $this->Campaign->validator()->add('advertiser_id', 'notEmpty', array(
    'rule' => 'notEmpty',
    'required' => true,
    'message' => 'Assigning an advertiser is required'
    ));

    When the model saves ($this->Campaign->save($this->request->data)), the
    validation list does not appear to have the new validation rule in it. I
    have traced out the validation set that the validator is using at save, and
    it is using only the validation rules that were initially set in the model.

    Any ideas? Am I going about this the wrong way? Am I missing anything?

    The Book only show examples being done from within a Model class. Can we
    not use this API from the Controller?

    Any insight is appreciated.

    AD
    --
    Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
    Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


    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
  • Lukman Hussein at Nov 29, 2012 at 6:54 am

    When the model saves ($this->Campaign->save($this->
    request->data)), the validation list does not appear to have the new
    validation rule in it. I have traced out the validation set that the
    validator is using at save, and it is using only the validation rules that
    were initially set in the model.
    try;
    $this->Campaign->save($this->request->data, *array('validate' => false)*)


    On Thursday, 21 June 2012 08:23:33 UTC+8, Adam Duro wrote:

    I am trying to use the CakePHP 2.2.0-RC2 dynamic validation API to create
    a new validation rule for a Model via a Controller.

    First of all, is this possible at all?

    So far when I try and run this in a controller:

    $this->Campaign->validator()->add('advertiser_id', 'notEmpty', array(
    'rule' => 'notEmpty',
    'required' => true,
    'message' => 'Assigning an advertiser is required'
    ));

    When the model saves ($this->Campaign->save($this->request->data)), the
    validation list does not appear to have the new validation rule in it. I
    have traced out the validation set that the validator is using at save, and
    it is using only the validation rules that were initially set in the model.

    Any ideas? Am I going about this the wrong way? Am I missing anything?

    The Book only show examples being done from within a Model class. Can we
    not use this API from the Controller?

    Any insight is appreciated.

    AD
    --
    Like Us on FaceBook https://www.facebook.com/CakePHP
    Find us on Twitter http://twitter.com/CakePHP

    ---
    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.
    Visit this group at http://groups.google.com/group/cake-php?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcake-php @
categoriesphp
postedJun 21, '12 at 11:48a
activeNov 29, '12 at 6:54a
posts4
users4
websitecakephp.org
irc#cakephp

People

Translate

site design / logo © 2022 Grokbase