![]() |
I'm new CI and the MVC pattern. I'm making a simple app to track my nicotine intake by storing usage into a database and displaying that data in the form of charts (using Chart.js)
Without getting too detailed, I have this in my app/Config/Routes.php: PHP Code: $routes->get('/new', 'PageController::newDataForm', ['filter' => ['authfilter', 'csrf']]); I currently house my HTML forms inside PageController as xxxxxxxForm(). The forms POST to DataPointController::xxxxxxEndpoint(), where it interacts with a DataPointModel to add the data into the DB. Is the above practice considered abnormal or bad? Should I rewrite the code to have all my HTML-related code and Database-inserting-code housed within PageController (and get rid of DataPointController)? When I originally created this app, it seemed to make sense to me because the HTML forms are all in a "PageController" and the database stuff is all in a "DataPointController".... but now I'm not so sure. The problem I perceive now is when invalid data gets POSTed, I have to `return` from DataPointController using `return (new PageController())->newDataForm()` instead of `$this->newDataForm()`. I have a feeling that this is inefficient and/or using more memory than necessary since its creating a new instance of PageController from within DataPointController. Thoughts? Recommendations?
This may help you understand MVC a little better.
Get to know MVC better and learn why it's so great. Dev.to - PHP MVC: the easy way What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Let me know how you make out with this.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(07-11-2024, 03:32 AM)InsiteFX Wrote: Let me know how you make out with this. Originally I was housing a lot of pages in the PageController, so I ended up significantly increasing the number of Controllers I had (1 for each page). As well as rename some of the Views to match the function-name in the Controller. Now the code feels a lot less cluttered ![]() I'm really impressed with how CI is built.. very extensible, easy to use, and extremely feature-rich! I'm hooked.
Glad things worked out for you.
I started way back with CodeIgniter version 1.6.x. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |