1
<?php
class PluginModel extends PluginAppModel {
public function hello(){
$anotherModel =& ClassRegistry::init('Plugin.PluginAnotherModel');
$this->read();
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$db->begin($this);
$anotherModel->create(array('AnotherModel' => $this->data['PluginModel']));
$anotherModel->save();
$db->commit($this);
}
}
?>
該腳本使用ClassRegistry :: init()函數調用另一個模型。抓取當前模型的數據並將其放入另一個模型的create()中。 當它試圖保存時,我得到一個SqlServer錯誤轉換爲日期時間字符。 當我調試數據時,它顯示INSERT日期時間格式爲'Y-m-d',但是在我的app/model/datasource/Sqlserver.php中,我指定了datetime ='Ymd'。ClassRegistry :: init不從數據源中拾取日期時間格式
爲什麼datetime格式不被拾取?它在正常的模型保存上按預期工作,但是當我使用ClassRegistry :: init函數調用另一個模型時不能運行?
我有一個工作周圍循環數據集保存之前將任何日期時間字段轉換爲'Ymd',但這聽起來不像是正確的方式嗎?
謝謝。
您應該始終提及您正在使用的確切cakephp版本。 – mark
對不起,這是版本2 – user2453502
你可能會減少你的整個方法2線..爲什麼所有的開銷? – mark