Welcome Guest, Not a member yet? Register   Sign In
Best Practices...
#1

[eluser]mikepuerto[/eluser]
Hi,

I have an "add()" method in a controller for inserting records into a DB. This method loads the view with the form, "http://example.com/controller/add". Right now I also have another method("insert()") that handles validating the data and then passes it to my model. So the form is posting to "http://example.com/controller/insert".

My question: From a best practice point of view, does it make sense to have two methods? It just seems weird to me that I have a method with the sole purpose of showing a view... Is this how it should be done? Is there a better way to do it?

Thanks!
Mike
#2

[eluser]adamp1[/eluser]
It depends on how complex the methods are. If both methods are under 20 or so lines combined, I would combine them. But if you are having to do lots of pre/post processing then by all means re-factor them out.

Now on the other hand if you know this form could be submitted through ajax then splitting the methods out makes sense (since you don't want the ajax method calling a method which displays a view if it goes wrong)




Theme © iAndrew 2016 - Forum software by © MyBB