Comments (2)
Maybe it's a good idea to take a look at Pixel and Tonics easy and clever solution for this problem in their services, helpers, elements and so on.
They mostly don't use it.
There are only a few uses of the request component in their code because that's the "correct" design pattern of an MVC. The controller should handle the request and the controller knows what kind of request it is - because you separate them in console and web controller. After your controller handled iti you should ry to avoid relying on it too heavily.
When you only pass the variables you need you won't get in trouble. Besides that you should check what kind of request you have in order to use the correct response component.
If your code end up with those if conditions all over the place maybe it's worth the rethink the design pattern (not talking about you in particular, just in general way)
Don't get me wrong - I can totally understand your point and I got to deal with it too in the past but when you structure your classes in a certain way from the beginning you won't have that much to worry. Of course it's "easier" to grab variables from request nearly everywhere instead of passing them all the way to the service but it's sometimes the cleaner approach
from docs.
@Anubarak Yep, agreed with your points.
In my case I'm mostly fighting against this not in my own code, but in plugins I'm using.
So, I think whatever the solution is, I think something in the docs specifically advising devs would be ideal.
from docs.
Related Issues (20)
- 404 from a link on Stack Overflow to what used to be at craft.request#getQueryString
- [5.x]: Stores - location in twig HOT 1
- [5.x]: Commerce - Addresses - wrong link
- [Content]: Craft - Addresses - Example - typo in example
- [Content]: Note Content-Type inference for template extensions
- [Content]: Get info about single country from country repository HOT 1
- [4.x]: Broken link in documentation HOT 1
- [Bug]: Styling issue
- [5.x]: GraphQL ping example needs an enabled, queryable schema HOT 4
- [Content]: docs for v5 still mention Field Groups
- [Content]: entry authors are available in Teams edition too
- [Content]: Commerce 5 event generator - incorrect class for EVENT_AFTER_RENDER_PDF
- Optimisation link doesn't exist
- [5.x] [Broken Link]: Extend GraphQL - craft\base\Element::gqlMutationNameByContext()
- [Content]: Mention `asyncCsrfInputs` config setting in `csrfInput()` Twig reference
- Step 5 of install
- [Content]: Promotable explanation for Products/variants
- Broken link to "updating" under deploy documentation
- [5.x]: Missing Documentation for Setting Up Two-Factor Authentication in Front-End Forms Description: HOT 2
- Incomplete Documentation for requireBillingAddressAtCheckout and requireShippingAddressAtCheckout Settings HOT 4
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 docs.