2

I have update into my project the last version of cakephp core. Now I get this error:

Deprecated (16384): SessionHelper has been deprecated. Use request->session() instead. [CORE/src/View/Helper/sessionHelper.php, line 39]

The error I think is in this line:

if ($this->session->read('admin_logged_in')){

What should I use instead?

Thanks

3
  • 1
    Don't want to be a smart ass, but the error message tells you, doesn't it? "... Use request->session() instead ..." Commented Sep 19, 2015 at 13:41
  • The message tells you! “Use request->session() instead.” Commented Sep 19, 2015 at 13:50
  • I have used $this->request->session->read but return me errors: Call to a member function read() on a non-object @ndm Commented Sep 19, 2015 at 16:16

2 Answers 2

6
if ($this->request->session->read('admin_logged_in')){

should be fine.

UPDATE

As per the comment of @raph below the correct answer is

$this->request->session()->read('admin_logged_in')

Note the () after session

Sign up to request clarification or add additional context in comments.

5 Comments

It returns error: Call to a member function read() on a non-object
Where do you call it? In controller?
if ($this->request->session()->read('admin_logged_in')){ - "session()" is a method, not a property - my mistake :)
... But, in 3.6, show this message: Deprecated (16384): ServerRequest::session() is deprecated. Use getSession() instead. The setter part will be removed.... Update to: $this->request->getSession()->read('admin_logged_in')
Above answer is correct for cakephp 3.6 and prior. In Cakephp 3.7, session() changes to getSession
1

In Cakehp 3.7, use getSession() instead.

$this->request->getSession()->read('admin_logged_in');

Ref: https://book.cakephp.org/3.0/en/development/sessions.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.