【问题标题】:Saving data to a new row将数据保存到新行
【发布时间】:2012-04-23 10:03:20
【问题描述】:

我有一个使用 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 方法,但是这段代码没有将数据保存到我的表中。这段代码有什么问题?

【问题讨论】:

  • 保存后试试var_dump($this->Temporary->invalidFields());
  • 结果还是一样,它没有将数据保存到表中..但是感谢您的回答。
  • 这只是为了帮助你调试...

标签: cakephp cakephp-1.3


【解决方案1】:
$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);

【讨论】:

    猜你喜欢
    • 2013-08-28
    • 2014-03-04
    • 1970-01-01
    • 1970-01-01
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-24
    • 2013-06-11
    相关资源
    最近更新 更多