gpt4 book ai didi

php - Cake php 模型验证不工作

转载 作者:行者123 更新时间:2023-11-29 03:40:22 25 4
gpt4 key购买 nike

我想在表中插入记录。为此,我有模型、 View 和 Controller 。我的代码中的所有内容都运行良好,但我的验证模型代码未显示任何验证消息。我该怎么办?我在下面给出代码:

我的 Controller 代码:

    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.'
),
);

}

最佳答案

在你的 Controller 中使用它:

if($this->Agent->validates($this->data)) {

代替:

if(empty($this->data) == false)

关于php - Cake php 模型验证不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14868147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com