我是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.'
))
);
Controller不保存任何值,因为nameOnCard是必需的。意味着验证发生但它没有显示任何错误消息。我已经应用了同一个控制器中具有不同型号名称的另一个动作,它在那里工作正常。然后这个动作会发生什么?
任何帮助表示感谢。
由于
答案 0 :(得分:0)
一些建议
public $ name =“prc_renewal_cards”;应该是公开的$ name =“Cardrenew”;
显示您的观看代码会很有帮助。