I have recently started using CodeIgniter, and I can see its benefits.
I am however seemingly encountering a few conceptual problems which are confusing me.
For some things CodeIgniter is making relatively simple things ridiculously hard.
Take for example a registration form whereby on inputting a username it checks its availability, and automatically informs you..
My approach to this is as follows.
A controller 'Account' with a function 'register' which loads a view 'register_form' which has jquery included, and my custom javascript.
My custom javascript passes the username typed in to a function called 'username_check' in the 'Account' controller which passes the value to the function 'username_check' within my model 'user_model' which returns a count of rows with that username which is then passed to a vi开发者_如何学Cew which outputs 'taken' or 'available' dependent on the count. It is then this response view which is placed into a div by the javascript.
Now... I struggled to write that down.. it baffles me just reading it, And conceptually it takes me about 10 minutes every time i want to add something just to find what i should be adding it to..
Can someone please tell me I have missed the point, and tell me how to implement this functionality.. correctly..
Thanks
It seems that you're new to the MVC concept. When I started using CI I designed a basic illustration that helped me understand MVC. After practice CI will make a lot of sense, namely the MVC pattern.
Your approach is correct. For me it makes sense to write code in the order that a user interacts with your website. Start with the view, then controller, and lastly model.
I recommend that you read the documentation thoroughly and just practice. Afterwards post your code.
I believe your thinking is quite correct. Model should take care of data (in your case it queries the db) while view should handle displaying of the data in whatever form it is.
精彩评论