'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>
これは、ビュー ファイル内のコードです。