

Failed to get a session component inside AppController
source link: https://www.codesd.com/item/failed-to-get-a-session-component-inside-appcontroller.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Failed to get a session component inside AppController
I need to get the roles of a user from the database.
I want to do it once and before everything. So I call a function from AppController constructor, which uses the session component. The function is given below
public function getRoles() {
if ($this->Session->check('user_name')) {
$username = $this->Session->read('user_name');
$userdesc = $this->Session->read('user_desc');
if ($userdesc === 'Student') {
$this->roles['Student'] = true;
} elseif ($userdesc === 'Faculty') {
$this->roles['Teacher'] = true;
$this->loadModel('UserRole');
$userRolesList = $this->UserRole->getUserRolesList($username);
$this->loadModel('Role');
$rolesList = $this->Role->getRolesList();
foreach($userRolesList as $userRole)
{
$this->roles[$rolesList[$userRole['UserRole']['role_id']]] = true;
}
}
}
}
I load session component using an array. But I can't use $this->Session
. If I load the component on the fly the function gives other errors. But if I call this function from beforeFilter() it creates no problem. Why I can't do it inside the constructor?
you cant use $this inside constructor as $this is not instanciated yet. explained here PHP: using $this in constructor
Recommend
-
10
NASA will fly Orion deep-space crew capsule ‘as is,’ despite failed component The agency claims there is enough redundancy in the system ...
-
8
Analysing micro-expressions from a (failed) user testing sessionIn a recent professional experience, I was unexpectedly sent to Spain for a user test of a system I did not design with the promise of a translator. Once ther...
-
7
#Featured #Android12 #GoogleIOTop 12 tips...
-
4
Testing a command inside a docker container (or getting an interactive session) I’ve used Docker but know very few commands (my favorite command being “docker prune”, to clean up images on a machine). Here’...
-
35
VirtualBox: Failed to open/create the internal network 'HostInterfaceNetworking-en0' (VERR_SUPDRV_COMPONENT_NOT_FOUND)
-
7
Giving Thanks and Giving Back (*gift* inside: book a 30 min UX Q&A session w/ me!)Let me start off by saying “UX Design” was never part of ‘the’ plan.I studied art history to bring a voice to people or groups of...
-
17
May 12, 2022 Reflecting on things I failed to get done at Google A meditation on corporate frustration & autonomy I’m kind of obsessed with how to g...
-
11
How to Fix Elden Ring's "Failed to Join Session" Error on Windows By Aman Kumar Published 5 hours ago Elden Ring...
-
6
“Nutritious and Delicious.” Inside YouTube’s Early, Failed Attempt To Recommend Videos That Are Good For You, And Enjoyable Too.Well before the social media backlash, YouTube tried to recommend videos...
-
1
Hibernate中Session的get和load 精选 原创 是温度呀 2022-09-22 11:16:44...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK