public static function generate($model, $overwrite = false) { if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'CrudArray')) { File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'CrudArray', 0777); } $file = APPLICATION_PATH . DS . 'models' . DS . 'CrudArray' . DS . ucfirst(Inflector::camelize($model)) . '.php'; if (!File::exists($file) || $overwrite) { $db = amodel($model); $crud = new Crud($db); File::delete($file); $tplModel = fgc(__DIR__ . DS . 'Model.tpl'); $tplField = fgc(__DIR__ . DS . 'Field.tpl'); $fields = $crud->fields(); $singular = ucfirst($model); $plural = $singular . 's'; $default_order = $crud->pk(); $tplModel = str_replace(array('##singular##', '##plural##', '##default_order##'), array($singular, $plural, $default_order), $tplModel); $fieldsSection = ''; foreach ($fields as $field) { if ($field != $crud->pk()) { $label = substr($field, -3) == '_id' ? ucfirst(str_replace('_id', '', $field)) : ucfirst(Inflector::camelize($field)); $fieldsSection .= str_replace(array('##field##', '##label##'), array($field, $label), $tplField); } } $tplModel = str_replace('##fields##', $fieldsSection, $tplModel); File::put($file, $tplModel); } }