Comments (4)
In this case, I would fetch the needed records from the database as an array using the Repository methods. Then loop and map this array(s) into the needed data structure (also an array) in a custom Service class. Let the JsonRenderer convert this Domain result into a JSON response.
Edit: This skeleton has been updated. You can find new up2date examples.
from slim4-skeleton.
Ok so fetch raw data from Repo and then transform it in service class. Would I use multiple data classes and combine them into an array in the service? I appreciate the help!
Example
ProductData
- Title
- Price
- ProductCategoryData
- Title
- Id
- Slug
- ProductBrandData
- Title
- Id
- Slug
from slim4-skeleton.
If you use the results from the repository only in this specific context (service, use case), an extra data class is not needed, because the scope of the data is so small that there is no real benefit to add extra classes for it. Of course, it depends on your specific use case.
from slim4-skeleton.
I just found this video that explains when and how you can / should use DTOs:
Data Transfer Objects - What Are DTOs
There is also this blog post about this topic:
Stop returning arrays, use objects instead
But he also says that:
You should also consider returning an array if the call is solely internal (between protected methods, for example); value objects should be used for external calls, but arrays are perfectly suitable for internal calls.
This is how I do it in practice as well. I prefer to return arrays from a repositories' method (for a list of records), but if I want to carry data over multiple places I prefer to use objects (DTO's) instead.
I'm closing this issue for now. If you have any further questions, feel free to ask.
from slim4-skeleton.
Related Issues (20)
- Install troubleshooting HOT 2
- Wrong statement in the configuration doc page HOT 4
- Database migrations with phinx and schema.sql generation HOT 5
- Which session package should I use? HOT 4
- Missing TemplateRenderer/HtmlRenderer HOT 2
- Question: MVC vs ADR Pattern HOT 2
- Link in docs is wrong HOT 1
- logger test's settings are useless HOT 4
- How to use loggerFactory in Routing/JwtAuth
- Using skeleton in a subdirectory HOT 2
- Error add slim/twig-view (composer require slim/twig-view) HOT 2
- create-project is not downloading some files HOT 3
- Problem getting JWT to work as per your eBook HOT 6
- Undefined function 'uuid_create' in LoggerFactory HOT 2
- 404 in /docs/configuration.md HOT 2
- How to handle query error ? HOT 5
- Add demonstration URL HOT 5
- Letting the bin/console.php setup command have non-interactive mode HOT 5
- Any auth in your sceleton? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slim4-skeleton.