0
'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>

这是视图文件中的代码。

4

1 回答 1

0

'on' => ''除非您仅指定创建或更新,否则您不需要添加。

尝试完全删除该部分。此外,请确保在编辑时将字段的数据正确传递给模型。在控制器的编辑方法中,在顶部添加一个调试以打印出数据并检查它实际上是否在正确的字段中通过:

debug($this->request->data);

否则,请发布您的控制器的编辑方法和您的视图代码。

于 2012-11-19T12:01:08.267 回答