PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/views/scaffolding/crud/model.php

http://github.com/fuel/oil
PHP | 35 lines | 29 code | 6 blank | 0 comment | 2 complexity | 7cb4c8ae20dc8be001e53847573e3765 MD5 | raw file
  1. <?php echo '<?php' ?>
  2. class Model_<?php echo $model_name; ?> extends Model_Crud
  3. {
  4. protected static $_table_name = '<?php echo $table; ?>';
  5. public static function validate($factory)
  6. {
  7. $val = Validation::forge($factory);
  8. <?php foreach ($fields as $field): ?>
  9. <?php
  10. $rules = array('required');
  11. if (in_array($field['type'], array('varchar', 'string', 'char')))
  12. {
  13. if ($field['name'] === 'email')
  14. {
  15. $rules[] = 'valid_email';
  16. }
  17. $rules[] = ! is_null($field['constraint']) ? "max_length[{$field['constraint']}]" : 'max_length[255]';
  18. }
  19. elseif (in_array($field['type'], array('int', 'integer')))
  20. {
  21. $rules[] = 'valid_string[numeric]';
  22. }
  23. $rules = implode('|', $rules);
  24. ?>
  25. $val->add_field('<?php echo $field['name']; ?>', '<?php echo ucwords(str_replace('_', ' ', $field['name'])); ?>', '<?php echo $rules; ?>');
  26. <?php endforeach; ?>
  27. return $val;
  28. }
  29. }