# |
May 17th 2021, 20:42 |
khalil |
I actually didn't know that, let me give it a try, thanks a lot |
# |
May 17th 2021, 20:42 |
khalil |
@ndm thanks! You mean if I set a view variable in appcontroller's beforeFilter for example, it can accessed in any template? |
# |
May 17th 2021, 20:35 |
ndm |
Components have access to the controller, so you could for example set a view variable, or a request attribute. |
# |
May 17th 2021, 20:26 |
slackebot |
use it in views and controllers, what would be the best approach in that case? |
# |
May 17th 2021, 20:26 |
khalil |
Now the $currency variable before being set, I'm doing a lot of logic, so I currently have it in a custom component (I check if the user is logged in and pull the currency from his account, if not, I check if there is a cookie "currency" saved and return it, if not, I convert his ip to his currency, and I save it in a cookie and return the value, I don't want to duplicate this logic in a helper and in a component in order to |
# |
May 17th 2021, 20:24 |
khalil |
The issue I'm facing, is that I want to access this currency everywhere, literally everywhere, in the views, templates, components, and controllers |
# |
May 17th 2021, 20:24 |
khalil |
Everything is set for the multiple currencies conversion etc.. But what I'm trying to do is, even if the user is not logged in, I'm converting the site currency to their local currency (mapping ips to countries to currency to conversion rate) This is also working perfectly |
# |
May 17th 2021, 20:22 |
khalil |
I'm building an ecommerce website that supports multiple currencies |
# |
May 17th 2021, 20:22 |
khalil |
I have a quick question more on the structure side of things in Cake |
# |
May 17th 2021, 20:22 |
khalil |
Hello guys! |
# |
May 17th 2021, 19:28 |
kevin.pfeifer |
basically: what do you want to achieve with that function ,:) |
# |
May 17th 2021, 19:27 |
kevin.pfeifer |
ok well there are many ways to set it, i was just rememberg the way via controller but it can be off course changed in the view as well |
# |
May 17th 2021, 19:25 |
kevin.pfeifer |
but setting the layout should happen in the controller (as far as I remember, haven't used it very often) |
# |
May 17th 2021, 19:25 |
kevin.pfeifer |
basically any custom functions you want to use in your template can be added to `src/View/AppView.php` and are avaialbe in your templates file via `$this->myCustomFunction()` |
# |
May 17th 2021, 19:24 |
kevin.pfeifer |
well your gist link is 7 years old so I wouldn't believe it will be working out of the box with current cake4 But as far as I understand that function it "just" tells you the path and filename to the coresponding layout template according to the prefix set in the request |
# |
May 17th 2021, 19:19 |
etibor |
@kevin.pfeifer would you tell me how view function can be use? |
# |
May 17th 2021, 19:10 |
kevin.pfeifer |
mhmm ok |
# |
May 17th 2021, 19:06 |
ovidiu.marinoiu |
```<?=$this->Html->meta('favicon.ico', '/paper_layout/favicon.ico', ['type' => 'icon']) . "\n";?>``` this works ;) |
# |
May 17th 2021, 19:06 |
ovidiu.marinoiu |
yeah, it looks like I was missing an "/" |
# |
May 17th 2021, 18:31 |
kevin.pfeifer |
ok and on authentication as well https://github.com/cakephp/authentication/issues/387 |
# |
May 17th 2021, 18:30 |
kevin.pfeifer |
there once was an issue at least in the authentication repo about that https://github.com/cakephp/authorization/issues/62 |
# |
May 17th 2021, 18:30 |
ndm |
https://cakesf.slack.com/archives/C053DPNGT/p1620855047163100 |
# |
May 17th 2021, 18:29 |
ndm |
You have to implement your own handler class, respectively extend one, and set a message either in the session (pre CakePHP 4.2), or on the requests flash object (CakePHP 4.2+) |
# |
May 17th 2021, 18:28 |
ndm |
Right now it's really anything but straightforward. |
# |
May 17th 2021, 18:28 |
ndm |
I would also vote for someone implementing configurable flash messages for both authentication and authorization middleware |
# |
May 17th 2021, 18:27 |
kevin.pfeifer |
i just remembered that we talked about that not long ago :,) |
# |
May 17th 2021, 18:27 |
ndm |
I knew this would come up again :) |
# |
May 17th 2021, 18:26 |
kushan |
yeah :) what's the best way to set a Flash message when redirect using configs set in unauthorizedHandler |
# |
May 17th 2021, 18:26 |
kevin.pfeifer |
and probably link a section in Request Authorization Middleware called “Handling Unauthorized Requests” to the already present one |
# |
May 17th 2021, 18:24 |
kevin.pfeifer |
so the doc improvement would just be to add that exception per default to the example code |
# |
May 17th 2021, 18:23 |
kevin.pfeifer |
thats cool |
# |
May 17th 2021, 18:22 |
kevin.pfeifer |
ok thx :) |
# |
May 17th 2021, 18:22 |
ndm |
The request authorization middleware as well as the authorization component throw `\Authorization\Exception\ForbiddenException`. |
# |
May 17th 2021, 18:22 |
kevin.pfeifer |
ah damn, how did i overlook that |
# |
May 17th 2021, 18:22 |
ndm |
In the `exceptions` of the `unauthorizedHandler` config. This defines what exceptions are being catched/handled. |
# |
May 17th 2021, 18:21 |
kevin.pfeifer |
in what list did you add that forbidden exception now? I am a bit lost now ,:) |
# |
May 17th 2021, 18:20 |
kushan |
@kevin.pfeifer @ndm thanks for your support :) |
# |
May 17th 2021, 18:20 |
kushan |
doc should be imprived |
# |
May 17th 2021, 18:19 |
kushan |
@ndm I've just tried what you said and it's Working :) |
# |
May 17th 2021, 18:19 |
kushan |
no i meant in the RequestAuthorizationMiddleware |
# |
May 17th 2021, 18:18 |
kevin.pfeifer |
https://github.com/cakephp/authorization/blob/master/src/Middleware/AuthorizationMiddleware.php#L64 |