Welcome Guest, Not a member yet? Register   Sign In
Creating a custom service/library
#1

Hi there,

I'm a newbie to CI4 so please bear with me. I'm building a small project and am keen on keeping my controllers small so intend to carry out input validation within my project's models.

It has been suggested that it may be good practice to pass back the result from a model's method (such as 'create') as some sort of result object. This object would contain fields to indicate whether the method failed or succeeded and could also contain an array of fields that did not validate, along with user-friendly error messages, etc, etc.

I think this sounds like a good idea. So my understanding is that each model should really tie to a field in the database so I shouldn't be creating a new result model. Instead it looks like I should be creating a result service and passing it into a model's method as a dependency.

I've read the CI4 documentation on creating services and could do with a little bit of guidance by way of an example. Or, tell me this is the wrong way of doing this.

Any help or pointers would be greatly appreciated.
Reply


Messages In This Thread
Creating a custom service/library - by Fido L Dido - 02-05-2020, 06:37 AM
RE: Creating a custom service/library - by x1250 - 02-05-2020, 08:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB