将数据保存到新行

时间:2012-04-23 10:03:20

标签: cakephp cakephp-1.3

我有一个CakePHP应用程序,我需要在表中插入一些数据行。我已经按照CakePHP书中的教程进行了操作,但它不起作用。

$this->Temporary->create();
$this->Temporary->set(
    array(
        'Temporary.position_id'=>$employeesAttribute[$arrCount][0]['EmployeeAttribute']['position_id'],
        'Temporary.person_id'=>$employeesAttribute[$arrCount][0]['StatusEmployee']['person_id'],
        'Temporary.job_id'=>$employeesAttribute[$arrCount][0]['Job']['id'],
        'Temporary.unit_id'=>$employeesAttribute[$arrCount][0]['Unit']['id'],
        'Temporary.person_code'=>$employeesAttribute[$arrCount][0]['StatusEmployee']['code'],
        'Temporary.name'=>$employeesAttribute[$arrCount][0]['Person']['first_name'].' '.$employeesAttribute[$arrCount][0]['Person']['middle_name'].' '.$employeesAttribute[$arrCount][0]['Person']['last_name'],
        'Temporary.job'=>$employeesAttribute[$arrCount][0]['Job']['short_desc']
    )
);
$this->Temporary->save();

我使用了create()方法,设置了变量并调用了save方法,但是这段代码没有将数据保存到我的表中。这段代码有什么问题?

1 个答案:

答案 0 :(得分:2)

$this->Temporary->create();
$data = 
    array(
        'Temporary' => array(
            'position_id'=>$employeesAttribute[$arrCount][0]['EmployeeAttribute']['position_id'],
            'person_id'=>$employeesAttribute[$arrCount][0]['StatusEmployee']['person_id'],
            'job_id'=>$employeesAttribute[$arrCount][0]['Job']['id'],
            'unit_id'=>$employeesAttribute[$arrCount][0]['Unit']['id'],
            'person_code'=>$employeesAttribute[$arrCount][0]['StatusEmployee']['code'],
            'name'=>$employeesAttribute[$arrCount][0]['Person']['first_name'].' '.$employeesAttribute[$arrCount][0]['Person']['middle_name'].' '.$employeesAttribute[$arrCount][0]['Person']['last_name'],
            'job'=>$employeesAttribute[$arrCount][0]['Job']['short_desc']
        )
    )
);
$this->Temporary->save($data);