How develop Model and validation - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: How develop Model and validation (/showthread.php?tid=75210) Pages:
1
2
|
How develop Model and validation - omid_student - 01-12-2020 Hi In this my project(Shop),there are 4 model (User,Shop,Order,Category) There is no problem I want to know only,is it correct validate function argument in model or i have to validate it in controller? Example I have User model with Login function This function have to arguments(username,password) Do i have to check username and password in Model or in Controller validate and then use model? Actually i want to know what is standard programming for use model and validation and split this from their RE: How develop Model and validation - deltatangodt - 01-12-2020 Better to do it in in controller. You model can then just process the data. RE: How develop Model and validation - omid_student - 01-12-2020 (01-12-2020, 04:20 PM)deltatangodt Wrote: Better to do it in in controller. You model can then just process the data.Yes i think so too Thanks RE: How develop Model and validation - asrofie - 01-13-2020 I think bettet create service class for handling logic process. You can use multiple model (example save log history), and also if you want to create REST Api login, you just call this service class. You can prevent duplicating code for login. Read ADR pattern. Hope this help RE: How develop Model and validation - jreklund - 01-13-2020 This depends on the person codeing it. If you are doing all validation in the Controller, you you need to duplicate it in every Controller. If you are doing it in the Model, you only need to do it ones. Here's an example how it's done in Codeigniter 4: https://codeigniter4.github.io/userguide/models/model.html#validating-data RE: How develop Model and validation - Mad Ox - 01-14-2020 (01-13-2020, 08:33 AM)asrofie Wrote: I think bettet create service class for handling logic process. You can use multiple model (example save log history), and also if you want to create REST Api login, you just call this service class. You can prevent duplicating code for login. Read ADR pattern. I would also second that because if I were you, I would do that because then service class would make my work easier.Also, it is easier to prevent duplication of login code. But then again, it really depends on you. RE: How develop Model and validation - omid_student - 01-15-2020 (01-13-2020, 11:49 AM)jreklund Wrote: This depends on the person codeing it. If you are doing all validation in the Controller, you you need to duplicate it in every Controller. If you are doing it in the Model, you only need to do it ones.I agree with you But in model,what to return to controller? Example: if (!'/\d+/',$mobile) return 'invalid'; or return -1; What one is correct? Thanks (01-13-2020, 08:33 AM)asrofie Wrote: I think bettet create service class for handling logic process. You can use multiple model (example save log history), and also if you want to create REST Api login, you just call this service class. You can prevent duplicating code for login. Read ADR pattern. Do you mean Hook? (01-13-2020, 11:49 AM)jreklund Wrote: This depends on the person codeing it. If you are doing all validation in the Controller, you you need to duplicate it in every Controller. If you are doing it in the Model, you only need to do it ones. I see relate link It is good way thanks RE: How develop Model and validation - jreklund - 01-15-2020 They should return a Boolean false or true. RE: How develop Model and validation - omid_student - 01-15-2020 (01-15-2020, 12:36 PM)jreklund Wrote: They should return a Boolean false or true. Of course RE: How develop Model and validation - InsiteFX - 01-16-2020 Always return true or false boolean that is the correct way of doing it. |