# |
May 17th 2021, 22:16 |
khalil |
@ndm nevermind! what you mentioned works perfectly, my issue was that I have multiple classes that extend AppController and a few classes underneath them, the inheritance wasn't done correctly, now everything is working fine! Thanks! |
# |
May 17th 2021, 22:01 |
khalil |
Whenever I try to access $currency in the template, i get undefined variable currency |
# |
May 17th 2021, 22:00 |
khalil |
And here's my AppController's beforeFilter: ```public function beforeFilter(EventInterface $event) { parent::beforeFilter($event); if(!$this->is('seller')) { $this->Flash->error('You are not allowed to access this location'); return $this->redirect('/'); } $currency = $this->Picked->currency(); $this->set('currency', $currency); $this->viewBuilder()->setLayout('my-shop'); }``` |
# |
May 17th 2021, 22:00 |
khalil |
Here's my AppController initialize method: ```public function initialize(): void { parent::initialize(); $this->loadComponent('Security'); $this->loadComponent('Picked'); }``` |
# |
May 17th 2021, 21:59 |
khalil |
I tried what you told me, and the variable is not accessible in the template files |
# |
May 17th 2021, 21:59 |
khalil |
Hey @ndm |
# |
May 17th 2021, 21:38 |
r.piel |
if it's Cake 3 you got an Entity with get(), try with setUser((array) $personeSesion) |
# |
May 17th 2021, 21:37 |
blackjccl |
@ndm What do you mean |
# |
May 17th 2021, 21:36 |
blackjccl |
@r.piel now my code is like this ```$personaSesion = $this->Persona->get($persona->id_persona); $this->Auth->setUser($personaSesion);``` and it follows the same error |
# |
May 17th 2021, 21:34 |
r.piel |
i hope ^^ |
# |
May 17th 2021, 21:34 |
r.piel |
it could be for transition |
# |
May 17th 2021, 21:33 |
ndm |
No no, very first things first is seeing the words "*plain text*" and "*password*" closer together than 12 kilometers and getting immediate PTSD :grimacing: |
# |
May 17th 2021, 21:32 |
r.piel |
first remove [] in get |
# |
May 17th 2021, 21:25 |
slackebot |
$this->redirect(['controller'=>'Evaluaciones','action'=>'instructions', $this->Auth->user('id_persona')]); }``` |
# |
May 17th 2021, 21:25 |
blackjccl |
```$persona = $this->Persona->findByTokenStringAndEstado($tokenLogin,1)->first(); if($persona andand (new DefaultPasswordHasher())->check($this->Password->getPlaintText($persona->plain_text),$persona->password)){ $personaSesion = $this->Persona->get([$persona->id_persona]); $this->Auth->setUser($personaSesion); return |
# |
May 17th 2021, 21:25 |
blackjccl |
Hello everyone can someone help me with this problem I get this error ```Argument 1 passed to Cake\Controller\Component\AuthComponent::setUser() must be of the type array, object given, called * @link http://book.cakephp.org/3.0/en/controllers/components/authentication.html#identifying-users-and-logging-them-in */ public function setUser(array $user)``` my code is the following |
# |
May 17th 2021, 21:16 |
khalil |
That was really helpful |
# |
May 17th 2021, 21:16 |
khalil |
Thanks @ndm I'll give it a try now, I'll let you know how it goes |
# |
May 17th 2021, 20:49 |
ndm |
But cells should inherit the current request object. |
# |
May 17th 2021, 20:48 |
ndm |
You don't even need to leave your component, it can can access the controller from within it. But sure, you manually bridge things from the controller too. In any case, view variables are available in all templates, except in cells I think. |
# |
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 |