【问题标题】:cakephp validation with another model使用另一个模型进行 cakephp 验证
【发布时间】:2012-10-26 01:53:49
【问题描述】:

我是 cakephp 新手,正在开发 1.3 版。我正在尝试从控制器验证表单,但它不起作用。这是我的控制器的操作代码: 控制器是cards_controller.php

class CardsController extends AppController {

            var $name = 'Cards';
            var $uses = array('Customfield','Customer','Parameter','Merchant','Merchantcard','Merchantcustomfield','Cardexist','Country','State','Customercontacts','Cardrenew');
            var $helpers =  array('Html','Form','Ajax','Javascript');
            var $components = array('Session','RequestHandler','RequestHandler','Auth');

    function index()
    {

    }



 function renewCard()
        {

         if($_SESSION['Auth']['User']['id'] == "")
                    {
                       $this->redirect("../users/login");
                    }

            $this->loadModel('Cardrenew');  

            $this->Cardrenew->set(array(
                      "customer_id" =>$id,
                       "merchant_id" =>$this->data['Card']['merchant_id'],
                       "merchant_card_id" =>$this->data['Card']
                                        ));                                  

                       if($this->Cardrenew->save())
                       {

                       }  
        }
    }


and here is the model code : 



class Cardrenew extends AppModel
    {
     public $name = "prc_renewal_cards";
     var $validate = array(
     'merchant_id' => array(
     'nameRule2'=>array(
     'rule'=> array('check'),
     'required' => true,
     'message'=>'Card already exists.'
     )),

    'nameOnCard' => array(
    'alphaNumeric' => array(
    'rule' => '/^[a-z0-9 ]*$/i',  // only 3 char (int or char  , no spaces in string)
    'required' => true,
    'allowEmpty'    => false,
    'message' => 'Please enter alphabets and numbers only.'
    ))

    );

控制器不保存任何值,因为 nameOnCard 是必需的。意味着验证发生,但它不显示任何错误消息。我在具有不同型号名称的同一控制器中的另一个动作上应用了相同的东西,它在那里工作正常。那么这个动作会发生什么?

任何帮助表示赞赏。

谢谢

【问题讨论】:

    标签: cakephp-1.3


    【解决方案1】:

    几个建议

    公开 $name = "prc_renewal_cards";实际上应该是 public $name = "Cardrenew";

    显示您的视图代码会很有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-02
      • 1970-01-01
      相关资源
      最近更新 更多