Can I set the user’s timezone in the layout file and let that flow through to the view files? Because it’s not working for me, but I suspect I’m doing something wrong.
Let’s say I have:
views/layout/main.php
views/something1/detailview1.php
views/something2/gridview2.php
in views/layout/main.php, I have:
Yii::$app->formatter->timeZone = $user->timezone
So anything my layout shows is in the user timezone. Anything in views/something1/detailview1.php or views/something2/gridview2.php is in UTC (my default). I am using attribute defs like: 'someattr1:datetime'.
If I move the timeZone setting above into each view file, then everything works. But, I’d much prefer to keep this in my layout file if possible to make it “global.”
View in MVC is for presentation. All such changes should be done in the controller and result, if any, passed to the view. Or if global then done in the configuration