'employees_firstname' => array(
'rule' => 'alphaNumeric',
'required' => true,
'allowEmpty' => false,
'on' => '',
'message' => 'This field is required'
)
这是我的验证。添加时效果很好。但是当我编辑时,即使该字段具有值,也会显示验证错误。什么问题?
function edit_employee($employees_id)
{
debug($this->request->data);
$business_accounts = $this->BusinessAccount->get_business_accounts();
$business_domains = $this->BusinessDomain->get_business_domains();
$designations = $this->Designation->get_designations();
$work_locations = $this->EmployeesWorkLocation->get_worklocations();
//$employees = $this->Employee->get_user_details();
$employees = $this->Employee->get_employee_details($employees_id);
$employees_details = $this->EmployeesDetail->get_employee_personal_details($employees_id);
$countries = $this->Country->get_countries();
$additional_data = array(
'business_accounts' => $business_accounts,
'business_domains' => $business_domains,
'designations' => $designations,
'work_locations' => $work_locations,
'supervisors' => $employees,
'countries' => $countries,
'employees' => $employees,
'employees_details' => $employees_details
);
$this->set($additional_data);
$this->set('title_for_layout', 'Calpinemate - Admin');
$this->layout = 'admin_console';
// echo $employees_id;
$this->Employee->id = $employees_id;
//$this->Employee->save($this->params['data']['Employee']);
//print_r($this->data);
if(!empty($this->data)){
if(isset($this->params['data']['add'])){
if($this->Employee->validates(array('fieldList' => array('employees_firstname','employees_lastname','employees_emailaddress','employees_password','employees_code','employees_mobile')))){
echo "IN";
$fileOK = $this->uploadFiles('img/Employees', $this->data['File'], $this->data['Employee']['employees_code']);
if (array_key_exists('urls', $fileOK)) {
$this->request->data['Employee']['employees_image'] = $fileOK['urls'][0];
}
$this->Employee->save($this->params['data']['Employee']);
$this->request->data['EmployeesDetail']['employees_id'] = $this->Employee->id;
$this->EmployeesDetail->save($this->params['data']['EmployeesDetail']);
$this->Session->setFlash("Employee Details Updated Successfully!");
$this->redirect('employee');
}
}
elseif(isset($this->params['data']['cancel'])){
$this->redirect('employee');
}
}
}
这是控制器中的功能
echo $this->Form->create('Employee', array('url' => array('controller' => 'MasterConsole', 'action' => 'edit_employee',$employees[0]['Employee']['employees_id']),'type' => 'file'));
<div class="listing1">
<div class="list_grid">First name</div>
<div class="list_grid7"><?php echo $this->Form->input('employees_firstname',array('type' => 'text','label' => false,'default' => isset($employees) ? $employees[0]['Employee']['employees_firstname'] : '')); ?></div>
</div>
这是视图文件中的代码。