Moving from CI3 - 4 |
Hey
I'm having a bit of an issue when attempting to rewrite a sloppy program I made in CI3 to CI4. I'm not the greatest coder, heck I struggled with Models hence why I never used them in CI3. (Sorry!) But want to make an effort now. Say I had this in CI3 in my Controller PHP Code: public function brewbeer() Then in my view i had this etc eg PHP Code: <?php foreach ($query->result() as $beer): ?> How best should this be done for CI4 as well as a model if needed? As some functions have changed and I'm struggling to get to grips with it. Should I handle error or redirect as I did before etc. How would you handle something like this?
Hello !
Here are some advices I would give you: 1/ I won't use things like "$this->uri->segment(3)", instead i would use routes definition: https://codeigniter4.github.io/userguide...aceholders 2/ I would use a model, yes. In CI3, I found it complicated, but in CI4 it is super easy: https://codeigniter4.github.io/userguide...your-model So, I would use routes placeholders to manage incoming requests, create a "BeerModel" to interact with the database (and fetch the content), use the controller to manage all this and send the result to the view. Please note that CI4 use a different way to load views: https://codeigniter4.github.io/userguide...ing-a-view |
Welcome Guest, Not a member yet? Register Sign In |