PageRenderTime 50ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/fuel/packages/oil/views/admin/crud/model.php

https://bitbucket.org/codeyash/bootstrap
PHP | 34 lines | 29 code | 5 blank | 0 comment | 2 complexity | 7bc072a062983022df5c4fad46bf589a MD5 | raw file
Possible License(s): MIT, Apache-2.0
  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', 'intenger')))
  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. }