Here you how does it work a view in Codeigniter – my personal explanation
About VIEWs in Codeigniter and in MVC frameworks, as newbie I gave myself an explanation about Codeigniter views mechanism good for MVC in general.
It would be great one day to find it in the Codeigniter Introduction on its official guides.
In my personal opinion and point of view, newbies should taught this:
In Codeigniter and in MVC you must forget VIEWS,
in MVC, views can be considered a sort of ”consequence”.
When you think about showing something to users, bear in mind that you won’t url to the HTML portion of what you will design in your MVC project (because sooner or later, you will create the “web views” to be shown to users, but…) :
you will not “load those HTML pages” in your browser with a “direct url”, forget html pages, forget VIEWs.
This is the tricky step to be modified in the newbie’s mentality.
Previous than MVC framework they were pages, now you are dealing with MVC, so think only about CONTROLLERS.
When you wanna think about something to be shown to users, bear in mind that it can “work” only by invoking a controller
because ONLY THE CONTROLLER will be the one that will finally call ”’a page”’, or the sequence of sections of a page, to be rendered in the browser (e.g. header, body, footer P.S: and think about them as stripes, not exactly as sections)
A Codeigniter app is ”’not made of views”’, you will ONLY INVOKE CONTROLLERS, they will be the CONTROLLERS’ “processes” (methods) that will (most of the times) end “calling their view” (not necessarily as singular, just to give the idea). AUGH!
You may laugh, but I lost hours before to got illuminated about this,
I was continuously “selfconfusingmyself” by having the same file name in the controller and in its related view AND SO
this is why in the earlier (again thinking about newbies) examples, the above concept should be enforced giving fancy no sense names to the files in the views folders,
making it sharp that the url mechanism is EXCLUSIVELY invoking controllers.
I apologize for my outbreak, I have read dozens of introductions about Codeigniter, but in no one I have ever found such a simple “explanation” and I’m wondering why.
No related posts.