douxin8749 2011-10-31 09:43
浏览 28
已采纳

cakePHP:验证控制器中的数据(hasMany)

I have the following problem:
I need to validate data in a controller, which is passed by a form. The special thing: The fields from the form are not present in the database, BUT in the $validate-Array. - Which should afaik not be a problem.
Another thing is, that the Model has a hasMany-Relationship with parts of this form.

Text hasMany Proofs

This is the validation-array:

var $validate = array(  
   'freetext' => array(  
      'between' => array(  
          'rule' => array('between', 250, 1000),  
          'message' => '..',  
      ),  
   ),  
);  

Here is an example of the data passed to the controller

[Proof] => Array
    (
        [0] => Array
            (
                [freetext] => asd
            )
        [1] => Array
            (
                [freetext] => asd
            )
        [2] => Array
            (
                [freetext] => asd
            )
    )

I use the following code to validate:

$this->Texts->set($this->data);   
if ($this->Texts->validates()) {  

When I call it, it returns true, so the validation succeed. BUT freetext has a bit less than 250 chars.

But: The form shows the red asterisks, which symbolizes me, that the validation-array is succesfully parsed an applied to the form.
And also in the corresponding controller beforeValidate() { debug($this->data); } shows me the correct data.

So WHY does data validation succeed, even when the policies are not me?

Thanks ahead!
~MxAgent

  • 写回答

2条回答 默认 最新

  • dongzg2006 2011-12-10 17:43
    关注

    Updated to cakePHP 2.0 and used validateMany() for validation. Now it works ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?