Welcome Guest, Not a member yet? Register   Sign In
Understanding the MVC and AJAX in CodeIgniter
#1

[eluser]ThatsJustMe[/eluser]
Hello,

1) I'm not exactly sure, for what are Controllers, in CodeIgniter, they are just for loading views and modules? For example, should I write all if statements in Controller, or should I do it in Module, and then just include it in Controller?

2) I've downloaded CodeIgniter AJAX library - and I would like to know, how should I make an AJAX db check for user, in registration form, for example, I would check the user input with jquery change() function, and then in for example validation.php file check if that user exists in database an return result. Should I make another view for that, with php content, or should I do that all in modules? Is there any example you could give to me, or maybe explain, since I'm not very familiar with MVC and AJAX, but I know that learning this will give me alot of bonuses Wink!
#2

[eluser]aquary[/eluser]
(1)
Normally, my controller do:
- Request models to pull data from database.
- Retrieve posted data.
- Sending request to other services, and vice versa.
- do some form validation (this could be in a model)
- redirect to some other pages
- Business logic/flows
- etc. anything not related to "Direct access to database" nor "Showing something to the user".

(2)
Just try to focus on the PHP script itself. How would the script do it task? Think of it and the script should be implemented that way. You want to check for user input with the database? so retrieve the data, check with the database, and return the result. Nothing is complicated. MVC is MVC, AJAX is AJAX. They are 2 separate entities working together.

I'd say instead of jumping right into AJAX, you should try making yourself familier with MVC first.




Theme © iAndrew 2016 - Forum software by © MyBB