17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1238 Views |
-
Session problem

12 September 2008 at 4:34pm Last edited: 12 September 2008 4:40pm
Hi All,
I have a Page_Controller class that extends ContentController. I tried to get the current user id by calling Member::currentUserId(), but it always returns 0. I looked at the code and saw that it called Session::get('loggedInAs'), so I tried calling that from my controller, still empty. If I print_r($_SESSION) it's there. Have I missed some trick or something that disallows sessions from ContentControllers?
My code is:
public function LoginLink()
{
$id = Member::currentUserID();
if ($id)
{
if (Member::isInGroup(1))
{
$link = 'admin';
}
else if (Member::isInGroup(2))
{
$link = 'partner-login';
}
else
{
$link = 'home';
}
return sprintf('<a href="%s%s">My Account</a>', Director::baseURL(), $link);
}
return '';
}and it's called from inside the template
-
Re: Session problem

12 September 2008 at 9:13pm
If you do a Debug::show(Member::currentMember()); you don't get anything at all? and your logged in?. Heh Ive done that trick before work out why I wasnt 'logged in' when I actually wasnt!
-
Re: Session problem

13 September 2008 at 10:22am
Tried the debug and nothing at all, just an empty white stripe at the top of the page. And yes, logged in, this is the results of print_r($_SESSION) from the same function:
Array
(
[FormInfo] => Array
(
[GFLoginForm_LoginForm] =>
[OpenIDLoginForm_LoginForm] =>
[Form_EditorToolbarImageForm] =>
[Form_EditorToolbarLinkForm] =>
[Form_EditorToolbarFlashForm] =>
)[MemberLoginForm] => Array
(
[force_message] =>
)[OpenIDLoginForm] => Array
(
[force_message] =>
)[lang] => Array
(
[site] => en
[cms] => en
)[BackURL] =>
[Security] => Array
(
[Message] => Array
(
[message] => Welcome Back, Stu
[type] => good
))
[loggedInAs] => 1
[SecurityID] => 652091318
)I don't really wanna access $_SESSION directly for this, but looks like I'll have to
-
Re: Session problem

15 September 2008 at 9:22am
OK, done more experimenting, I can make it work with:
$m = Member::currentUser();
$id = $m->getField('ID');
if ($id)
{ ... }but, it works from all pages but the home page, so I had to change it to:
$m = Member::currentUser();
if ($m && $id = $m->getField('ID'))
{ ... }this seems pretty crazy, why aren't session variables available via Session::get() from the homepage only.
The home page does have it's own controller, that extends the page controller, I've created a test page that uses the homepage controller, and it works, only difference in the pages are that there is a page segment for one of them
| 1238 Views | ||
|
Page:
1
|
Go to Top |


