Splitting responsibilities between controller and model |
I'm trying to work out the best way to handle the balance between controllers and models when migrating from CI3 to CI4.
It seems like the old system used the DataMapperExt class as the access to the underlying database. So previously I'd have: PHP Code: class Member extends DataMapperExt { Then that would be instantiated by a Member_model class like: PHP Code: class Member_model extends CI_Model { Then the controller would really just forward the data on from the form: PHP Code: class Member extends CI_Controller { In CI4 it appears that the validation and tidying up is done in the controller, or at least that's how the example at https://www.codeigniter.com/user_guide/t...items.html does it but the notes on models at https://www.codeigniter.com/user_guide/m...validation suggests that you can do it within the model itself. The latter seems a bit cleaner to me. The user model in CI4 now simply extends the core model detailing which database columns may be modified and whether there should be any validation on specific columns to make sure that someone doesn't try to enter too long a name or a negative age for example. That would mean my Member model now looks like: PHP Code: class Member extends Model { The controller would look similar to this... PHP Code: class Member extends BaseController { Have I got the above right? My thoughts are to have the validation done within my models as it's then available to whichever controller ends up using it. |
Messages In This Thread |
Splitting responsibilities between controller and model - by bobw - 03-04-2024, 03:47 AM
RE: Splitting responsibilities between controller and model - by InsiteFX - 03-04-2024, 04:51 AM
RE: Splitting responsibilities between controller and model - by bobw - 03-04-2024, 05:54 AM
RE: Splitting responsibilities between controller and model - by bobw - 03-04-2024, 11:53 AM
RE: Splitting responsibilities between controller and model - by kenjis - 03-04-2024, 06:20 PM
RE: Splitting responsibilities between controller and model - by bobw - 03-04-2024, 11:48 PM
|