When to put code in Controller and when in Model |
MVC pattern seems quite clear but sometimes I'm not sure where certain things should go - controller or model.
Examples that feel clear enough:
(01-21-2023, 10:42 AM)Rinart Wrote: You can move the logic to: - a library class - parent controller class - a trait (01-21-2023, 07:02 PM)kenjis Wrote:(01-21-2023, 10:42 AM)Rinart Wrote: Would it be a bad idea to move logic into an Entity? Like this: PHP Code: // App/Entities/Order.php
An entity represents a database record.
I think it should not know about File Uploading.
Create a new layer in folder Services, Helpers...:
class OrderService or class OrderCreator Add a method to it with your desired parameters: public function createOrderFromUser($user, $order, $file, $options, ...) and inside you work with several models (namely with a database), upload a picture, check validation and so on. In response, return either true/false or a new order with a picture. In controller call: PHP Code: $orderHelper = new OrderService();
Simple CI 4 project for beginners codeigniter-expenses
|
Welcome Guest, Not a member yet? Register Sign In |