Welcome Guest, Not a member yet? Register   Sign In
Time-Saving Function (Forms/Validation)
#1

[eluser]fancms[/eluser]
If you're like me, when creating a controller with add/edit functions you constantly find yourself coding something like

Code:
if($this->validation->run() == FALSE {
   $data["variable"] = $something;
   $this->load->view("add",$data);
} else {
  $add = $this->model_name->model_function($this->validation->variable,$something);
  //Display success message here
}

I'm impatient and loathe coding nearly identical lines over and over. So I created a function that helps me reduce the above to this:

Code:
$this->forms->validation_run("add",array("variable"=>$something),"model_name","model_function",array($this->validation->variable,$something));

The code can be found here: http://momgeek.wordpress.com/2008/10/06/...deigniter/
(edit: moved to my blog for easier tweaking to the code)
#2

[eluser]xwero[/eluser]
Simple function??? 6 parameters? and there is an optional parameter as second but there are required parameters after it?

Altough it can seem like a time saver i think there will be too many little differences to use the function.
#3

[eluser]fancms[/eluser]
By simple I meant that it really reduced the number of lines I had to keep creating. Hmm...guess that's really more of a "time-saving" thing :red: I should probably edit that... (edit: done)

You could move the $layout_template and $data_array variables at the end; however, it helped keep it clearer in my mind to do it in the order I listed them in.

It's certainly open to re-working and not everyone will have a need for it. For the app I'm working on it's really helped me speed up the add/edit portions in most of my controllers. I figured if I had a use for it someone else might too Smile




Theme © iAndrew 2016 - Forum software by © MyBB