Invalid php tap model check

I want to insert a record into a table. For this, I have a model, view and controller. Everything in my code works fine, but my model code for verification does not show any validation message. What should I do? I give below code:

My controller 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.' ), ); } 
+2
source share
3 answers

changes:

 $this->Form->create('Agents', 

to

 $this->Form->create('Agent', 

Since your Agent model name is not Agents . See Here: Model Verification

0
source

Use this in your controller:

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

Instead:

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

try the following:

  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()); } } 

Note: to register error checking, use this debug($this->Agent->validationErrors); .

0
source

All Articles