Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Model_Box extends ORM
- {
- public $_belongs_to = array('product' => array());
- public function formo()
- {
- return array
- (
- 'id' => array(
- 'editable' => FALSE,
- 'render' => FALSE,
- ),
- 'product' => array(
- 'orm_primary_val' => 'name',
- 'editable' => FALSE
- ),
- 'filename' => array(
- 'driver' => 'file'
- )
- );
- }
- public function rules()
- {
- return array
- (
- 'name' => array
- (
- array('not_empty')
- ),
- 'product_id' => array
- (
- array('not_empty')
- )
- );
- }
- // couldn't accomplish that otherwise, don't remember why though
- // something about validation fscking up everywhere like crazy
- // (could be my mistake though)
- // this method is run in _create_passed() callback in my kohana3-crud (I already had the code up and running when you coded callbacks into formo)
- public function validate_files($form)
- {
- $valid = new Validation($_FILES);
- $valid->rules('filename', array(
- array('Upload::not_empty', NULL),
- array('Upload::type', array(':value', array('jpg','png','gif'))),
- array('Upload::size', array(':value', '4M'))
- ));
- try
- {
- $this->check($valid);
- }
- catch(ORM_Validation_Exception $e)
- {
- $errors = $e->errors();
- foreach($errors['_external'] as $field => $error)
- {
- $form->$field->error($error[0]);
- }
- return false;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement