Skip to content

Instantly share code, notes, and snippets.

@tai-sho
Last active August 29, 2015 14:07
Show Gist options
  • Save tai-sho/01e2aa45da6b15bedb19 to your computer and use it in GitHub Desktop.
Save tai-sho/01e2aa45da6b15bedb19 to your computer and use it in GitHub Desktop.
CakePHP2.xでモデルの空配列を作る関数
<?php
App::uses('Model', 'Model');
class AppModel extends Model {
/**
* モデルの空配列を返します。
* @return array モデルの空配列
*/
public function getModelArray() {
//カラムタイプの配列からキーのみを取得
$keys = array_keys($this->getColumnTypes());
//配列を空文字で埋める
$arr[$this->alias] = array_fill_keys($keys,'');
return $arr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment