Welcome Guest, Not a member yet? Register   Sign In
newbie: Seperating Controllers Properly
#1

[eluser]matt_a[/eluser]
Hello everyone!

I'm quite familiar with PHP, however I just came to CodeIgniter and this is my first experience with the MVC pattern. So please, bare with me!

I'm concerned that my controller(s) are not designed properly. For example, controller functions that simply display a view vs. controller functions that process the data.

To make things a little more clear, I'm creating a "User" controller that interacts with my "User_model." Inside the controller, I have functions such as login(), which simply display the login view. When submitted, the data is passed to the User controller to a function called "verify_login." For some reason, it strikes me that login() should be doing both jobs.

As I'm typing this I see that my way of doing this probably isn't "wrong." I'm just a really paranoid programmer who likes to do things the most efficient way.

Does anyone have any suggestions?
#2

[eluser]Buso[/eluser]
I like checking if the post hast been submitted, so I can do both things in the same method:

Code:
if( ! $this->input->post('submit')) {
  // show the form
  return;
}
// process login

But your first choice is right too, it's a matter of taste
#3

[eluser]matt_a[/eluser]
:red:

It's as easy as that! After ditching procedural PHP and coming to OOP and CodeIgniter, I guess I forgot some of the very basics :ohh:

Thanks Buso.




Theme © iAndrew 2016 - Forum software by © MyBB