Single Responsibility Principal |
[eluser]xtremer360[/eluser]
This is what I am currently using for my submit function but it is doing way to much and I'm wanting to work with it so that I can apply the Single Responsibility Principle as well as I can see my code is suffering from Arrow Anti-Pattern and was looking for some ideas on how this could be improved. I had to include it in a link because the function was too big. http://pastebin.com/j2wnck6C
[eluser]Otemu[/eluser]
Hi, You could make better use of the Codeigniter Validation class, for instance you have a lot of Code: if (strtotime($user_data->lock_date) > $current_time) Quote:The validation system supports callbacks to your own validation functions. This permits you to extend the validation class to meet your needs. For example, if you need to run a database query to see if the user is choosing a unique username, you can create a callback function that does that So for instance to check status you could run a callback: Code: $this->form_validation->set_rules('username', 'Username', 'required|check_status'); Quite a few of your if else statements can also be changed to just switch statements. Then just use set_message for each one. You can also save sets of rules in a config file Form Validation Also check out Flattening Arrow Code and The Single Responsibility Principle
[eluser]xtremer360[/eluser]
I should mention this form is submitted with jQuery ajax function.
[eluser]xtremer360[/eluser]
Well with the user status that would display under the username field and I just want it to be a part of what is returned as the json output array. Here's what I have so far: Code: public function form_is_valid() [quote author="Otemu" date="1358157348"]Hi, You could make better use of the Codeigniter Validation class, for instance you have a lot of Code: if (strtotime($user_data->lock_date) > $current_time) Quote:The validation system supports callbacks to your own validation functions. This permits you to extend the validation class to meet your needs. For example, if you need to run a database query to see if the user is choosing a unique username, you can create a callback function that does that So for instance to check status you could run a callback: Code: $this->form_validation->set_rules('username', 'Username', 'required|check_status'); Quite a few of your if else statements can also be changed to just switch statements. Then just use set_message for each one. You can also save sets of rules in a config file Form Validation Also check out Flattening Arrow Code and The Single Responsibility Principle[/quote]
|
Welcome Guest, Not a member yet? Register Sign In |