PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 25, 2022

[FIXED] CakePHP 3: Why not to using Session in model

 January 25, 2022     cakephp, cakephp-3.0, php, session     No comments   

Issue

I think it is necessary to access the session data from every where especially in the model, I don't know what is the conflict with the design or logic of CakePHP.

I wonder if we can use the Session class globally as Text class.

Does the problem just about the design and logic and nothing related to errors can be rises in the future?


Solution

As per Framework concept you can read/write/modify session from Controller.But have not read and write access in Model.

In CakePHP v3 you can manage session in model as mentioned below

\Cake\Routing\Router::getRequest()->session()->read('key');
\Cake\Routing\Router::getRequest()->session()->write('key', 'value');


Answered By - Haresh Vidja
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing