Welcome Guest, Not a member yet? Register   Sign In
CI 2.1.0 form validation external callbacks via the newly available param
#9

[eluser]LeMec[/eluser]
Hello,

Thanks, for this skunkbad. I looked at your community auth and tried to take the My_form_validation and use it in my project.

I am using HMVC so it did not work.

I also have my models organized in sub directories so the code could not find the specified model.

I have made a few changes that seemed to fix the problem for me...

Code:
public function external_callbacks( $postdata, $param )
{
  $param_values = explode( ',', $param );

  // Make sure the model is loaded
  $model = $param_values[0];

  //Alain: See if there is a path...
  $model_path= explode( '/',$model );
  $model_segments= count($model_path );
  if ($model_segments > 1)
  {
   $modelObj=$model_path[$model_segments -1];
  }
  else
  {
   $modelObj=$model;
  }

  $this->CI->load->model( $model );

  // Rename the second element in the array for easy usage
  $method = $param_values[1];

  // Check to see if there are any additional values to send as an array
  if( count( $param_values ) > 2 )
  {
   // Remove the first two elements in the param_values array
   array_shift( $param_values );
   array_shift( $param_values );

   $argument = $param_values;
  }

  // Do the actual validation in the external callback
  if( isset( $argument ) )
  {
   //Alain: now using $modelObj
   $callback_result = $this->CI->$modelObj->$method( $postdata, $argument );
  }
  else
  {
   //Alain: now using $modelObj
   $callback_result = $this->CI->$modelObj->$method( $postdata );
  }

  return $callback_result;
}

Edit: I also need to enter the full path of where my model is in my validation rules...

So, if I did not enter a path, then this would not find the model, but If I entered a path, then it would find the model load it but when trying to use it it would reference the object with the path.


Messages In This Thread
CI 2.1.0 form validation external callbacks via the newly available param - by El Forum - 05-09-2012, 09:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB