蛋糕php模型验证不工作 [英] Cake php Model Validation Not Working

查看:94
本文介绍了蛋糕php模型验证不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在表中插入记录。对于这个我有模型,视图和控制器。我的代码中的任何工作完美,但我的模型代码验证不显示任何验证消息。我应该怎么办?代码:

I want insert record in a table.For this i have model,view and controller.Everything in my code is working perfectly but my model code for validation not showing any validation message.What should i do?I am giving below the code :

我的控制器代码:

    public function send_money()
        {

         $this->layout='agent';
         $this->Agent->create();
         $this->Agent->set($this->data);

           if(empty($this->data) == false)
            {
                //$this->Agent->saveAll($this->data['Agent'], array('validate' => 'only')); //This code Id New
                $this->Agent->saveAll($this->data['Agent']);
                $this->Session->setFlash('Information Added Successfully.');
                $this->redirect('send_money');

            }
            else
            {
                $this->set('errors', $this->Agent->invalidFields());    
            }

        }

And My Model Code is :



    App::uses('AppModel', 'Model');
    /**
     * Admin Login Model
     *
     */
     class Agent extends AppModel
     {
        public $name='Agent';
        public $usetables='agents';

        public $validate = array(

         'contact' =>array(
          'rule' => 'notEmpty', // or: array('ruleName', 'param1', 'param2' ...)
          'allowEmpty' => false,
          'message'    => 'Please Enter Contact No.'
        ),
         'name' =>array(
          'rule' => 'notEmpty', // or: array('ruleName', 'param1', 'param2' ...)
          'allowEmpty' => false,
          'message'    => 'Please Enter Name.'
        ),

         'email_add' =>array(
          'rule' => 'email', // or: array('ruleName', 'param1', 'param2' ...)
          'allowEmpty' => false,
          'message'    => 'Please Enter Valid Email.'
        ),
        );

     }


推荐答案

 public function send_money()
    {

     $this->layout='agent';
     $this->Agent->create();
     $this->Agent->set($this->data);

       if($this->Agent->saveAll($this->data['Agent'])) {
            $this->Session->setFlash('Information Added Successfully.');
            $this->redirect('send_money');
        }
        else {
            $this->set('errors', $this->Agent->invalidFields());    
        }

    }

注意:记录错误验证使用此 debug($ this-> Agent-> validationErrors);

Note : to log the error validation use this debug($this->Agent->validationErrors);.

这篇关于蛋糕php模型验证不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆