Comments (11)
Please note it's not static.
To be used: $this->app->t(...)
And Yii::t()
is not removed.
from yii-core.
The main point is "destatification" inside the framework core. While static methods can serve as good shortcuts for faster code composing, they encourage developers to rely on global application state, that is usually not a good thing. You don't like to use $_GLOBALS
variable, right?
There are some posts [1], [2] that explain problem a bit wider.
from yii-core.
@slinstj I think the problem is that Yii::t() is not pure function. Yii:t() behavior depends on settings. We can change the settings at any time and change the behavior.
from yii-core.
Which is better to use $this->app->t()
or Yii::t()
and why?
from yii-core.
Do you plan to remove Yii::t()
?
from yii-core.
Not now. And only after having very good alternative(s).
from yii-core.
At the moment we are only trying to clean up the framework core.
from yii-core.
Excelent "destatification" helpers also.
from yii-core.
Hi guys!
About the "destatification", as I was reading the pointed articles, I tended to discord of them. I think it could be just "over-engineering" to simple situations. When I got to the end of the article, many comments came with strong variated contrary arguments (like this).
I think the "Yeah, it is" could be lost if Yii3 "dificult" some simple things. And helpers are this: simple things. They have no state. They dont change states. They are simple functions.
It would be great to hear really "strong" arguments to remove (or substitute) static helpers, because I read the pointed articles and I could not find them (nor the most of the commenters). Hope to hear you here... thank you.
from yii-core.
@slinstj
First of all Yii::t()
is not about to be removed.
But things are being cleaned up.
$this->app->t()
will be used in the framework where possible.
And we recommend to use it this way.
It is more "clean" because Yii::t()
is not actually simple static stateless function, it just hides from you that some global Application
and I18N
objects are used behind the scene.
Getting $this->app
with constructor DI and then calling $this->app->t()
makes everything explicit hopefully without making troubles. But you are free to choose :)
I'm trying to bring modern approaches and more "clean" OOP while keeping "Yes, it is" style and soul.
P.S.
Finishing Yii 3.0 changes description. It will be available soon.
from yii-core.
Thank you @gagatust and @hiqsol.
I meant in my comment (maybe I had not been clear) was about remove "all" utilities/helpers for the sake of "destatification". This is what I think that would be "over-engineering". But in the answers I see this doesn't seem to be the intention. 👍
from yii-core.
Related Issues (20)
- `data` dirs in tests HOT 5
- Debug code in Model? HOT 3
- \yii\base\Application constructor parameter HOT 2
- 我认为yii3最应该解决的就是composer包过大的问题 HOT 2
- Should not require yii-web HOT 11
- Enhancement: BaseJson::decode supports decode options HOT 1
- Discuss: Do we still need controllers? HOT 2
- Enhancement: StringHelper::isEmpty() HOT 7
- can't visit yii forum site HOT 1
- Review helpers naming and usage HOT 33
- Url::ensureScheme should fail hard for non absolute paths HOT 2
- What is the current dependency between repo? HOT 20
- Yii3 assets path not correctly reference if installed in subfolder HOT 2
- SOLID compliance HOT 3
- Custom reference syntax to class or class member in comments make impossible to navigate in IDE HOT 19
- Change namespace to Yiisoft\Core? HOT 8
- When will yii3 be released? HOT 1
- Request to separate FileHelper from yii-core HOT 19
- Pack requirements checker into separate package HOT 1
- Repo merges into a repo and then splits 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 yii-core.