Welcome Guest, Not a member yet? Register   Sign In
form_validation in model
#1

[eluser]Unknown[/eluser]
hi, i need to perform validation, setting rules and message in model.

I use a model named MY_modelT that generates a form for insert and update data into table in db.

For each table i use a model i call {table}_model that extends MY_modelT

In {table}_model i create a public array with table structure, and form_validation rules.

form_validation library is autoloaded.

A simple example:

table_model
Code:
class table_model extends MY_modelT{
   public structureT = array("field1"=>array("as"=>"F1", "type"="int"));
   function validation(){
       $this->form_validation->set_rules('field1', 'F1', "callback_field1_check");
   }
   function field1_check($str){
       if(empty($str)){
           $this->form_validation->set_message('field1, "%s can't be empty");
       }
   }
}

In controller {table}_model::validation() is called but field1_check no...why?




Theme © iAndrew 2016 - Forum software by © MyBB