大家好,我正在创建一个发票系统,并试图确保发送请求的人将其发送给存在的人。我目前拥有的代码不起作用,想知道是否有人可以帮我一把。
模型
'exists'=>array(
'rule'=>'partytwo',
'message'=>'That username doesnt exist.'
));
function userExists($field=array(), $compare_field=null )
{
if($field['exists']= $compare_field)
return TRUE;
else return FALSE;
}
和控制器关系的验证
if($this->request->is('post')){
if($this->Relationship->validates(array('fieldlist'=>array('partywo','Relationship.userExists')))){
$this->Relationship->create();
if ($this->Relationship->save($this->request->data))
{
$id=$this->Relationship->id;
$this->Session->setFlash('The relationship has been saved');
}}
else { $this->Session->setFlash('The relationship could not be saved. Please, try again.'); }
}
这是我目前的模型
<?php
class Relationship extends AppModel{
var $name='Relationship';
public $useTable = 'relationships_users';
public $primaryKey = 'id';
var $validate = array(
'date' => array(
'rule' => array('datevalidation', 'systemDate' ),
'message' => 'Current Date and System Date is mismatched'),
'partytwo'=>array(
'partytwoExists'=>array(
'rule'=> 'userExists',
'message'=>'That username doesnt exist.'
)));
function datevalidation( $field=array(), $compare_field=null )
{
if ($field['date'] > $compare_field)
return TRUE;
else return FALSE;
}
function userExists($check)
{
$userExists= $this->find('count', array('conditions'=>$check));
if($userExists == 1)
{return TRUE;
}
else
return FALSE;
}
}
它目前直接出错