# |
May 29th 2017, 20:18 |
chris-andre |
> Method sessions does not exist |
# |
May 29th 2017, 20:17 |
lorenzo |
@chris-andre and what’s the error you’re getting? |
# |
May 29th 2017, 20:11 |
chris-andre |
Last try was with TableRegistry, as you can see. |
# |
May 29th 2017, 20:10 |
chris-andre |
@lorenzo Yes. Here is my controller action: https://gist.github.com/chris-andre/b22b1592702e5d3cc8081a3a74c7372c |
# |
May 29th 2017, 19:36 |
lorenzo |
are you sure you are executing that in the context of a controller? |
# |
May 29th 2017, 19:35 |
lorenzo |
`loadModel` is a method of all controllers |
# |
May 29th 2017, 19:19 |
chris-andre |
Can't sessions table be loaded like other tables/models? I have tried `TableRegistry::get()` as well. Worked inside a component, but not in my controller. Any ideas? |
# |
May 29th 2017, 19:18 |
chris-andre |
I'm trying to `$this->loadModel('Sessions')` in my controller, but I get > Method doesn't exists. |
# |
May 29th 2017, 17:45 |
JD-Robbs |
tell Blurb |
# |
May 29th 2017, 17:45 |
JD-Robbs |
~tell Test |
# |
May 29th 2017, 17:45 |
JD-Robbs |
test |
# |
May 29th 2017, 16:45 |
chris-andre |
If so, I have to do some custom code to add the user_id to the sessions table. Will look into it later. GF is pushing me out of my chair. Thanks @hmic |
# |
May 29th 2017, 16:41 |
chris-andre |
That is the table. |
# |
May 29th 2017, 16:40 |
chris-andre |
https://book.cakephp.org/3.0/en/development/sessions.html#database-sessions |
# |
May 29th 2017, 16:39 |
hmic |
you have the user_id in the sessiontable! |
# |
May 29th 2017, 16:39 |
hmic |
no |
# |
May 29th 2017, 16:39 |
chris-andre |
Yes, okay. Could do. Then I will have to look through every record until I have a match in Sessions.data |
# |
May 29th 2017, 16:37 |
hmic |
you don't. you do have the user_id in the session table, just delete the entry/ies that match the user that got changed |
# |
May 29th 2017, 16:37 |
chris-andre |
Right |
# |
May 29th 2017, 16:36 |
hmic |
well, usually you need the user session data to be reevaluated if you change something like their permissions. at least that is the example case... |
# |
May 29th 2017, 16:36 |
chris-andre |
Yes, but still I will need a join table to track the session |
# |
May 29th 2017, 16:35 |
hmic |
just ~3 lines of code in an afterSave event of the user table and you are done |
# |
May 29th 2017, 16:35 |
chris-andre |
Allright :slightly_smiling_face: Thanks. I doubt I can prove you wrong by now, so I guess I will go with deleting session. |
# |
May 29th 2017, 16:35 |
hmic |
- event on save of userdata. you can unconditionally delete that data from the session table, if the user is not logged in, it does not matter anyways. |
# |
May 29th 2017, 16:34 |
hmic |
if you think that is good practise too - just delete the session table entry with the user_id you have just changed |
# |
May 29th 2017, 16:34 |
hmic |
i don't consider anything besides that good practise! you might come up with a case that proves me wrong though :d |
# |
May 29th 2017, 16:33 |
chris-andre |
Okay. Should be okay. |
# |
May 29th 2017, 16:33 |
hmic |
the simple - and usual - thing to do, if *important* data on a user changes is just logging that user out! |
# |
May 29th 2017, 16:32 |
chris-andre |
Okay. Then we are on the same page. Can I ask, how should I update SessionsTable? By Auth->setUser()? Or is that considered wrong? |
# |
May 29th 2017, 16:29 |
chris-andre |
Allright. I misunderstood you. |
# |
May 29th 2017, 16:29 |
chris-andre |
Do you mean updating the user session (db) ? |
# |
May 29th 2017, 16:29 |
hmic |
updating the session data is about updating the session data, not the user data! |
# |
May 29th 2017, 16:28 |
chris-andre |
When I say updating user data, I mean updating data in the UsersTable |
# |
May 29th 2017, 16:28 |
chris-andre |
Wondering why data isn't changed when updating user data then :S |
# |
May 29th 2017, 16:28 |
hmic |
where else do you think the data would be stored? :d |
# |
May 29th 2017, 16:27 |
hmic |
yes |
# |
May 29th 2017, 16:26 |
chris-andre |
@hmic Are you sure database session reads user data upon each request? I can't see that it does. |
# |
May 29th 2017, 16:07 |
hmic |
so attach it to the controller, like i said instead (from the parent components initialize) and use like my code snipped above to make sure you don't miss any callbacks on your child component |
# |
May 29th 2017, 16:07 |
hmic |
last sentence! - no callbacks at all! |
# |
May 29th 2017, 16:07 |
hmic |
https://book.cakephp.org/3.0/en/controllers/components.html#using-other-components-in-your-component |
# |
May 29th 2017, 16:05 |
hmic |
additionally: missed callbacks will not be called as the docs state: https://book.cakephp.org/3.0/en/controllers/components.html#loading-components-on-the-fly |