我是 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 是必需的。意味着验证发生,但它不显示任何错误消息。我在具有不同型号名称的同一控制器中的另一个动作上应用了相同的东西,它在那里工作正常。那么这个动作会发生什么?
任何帮助表示赞赏。
谢谢