How can i access Session in Component?

Cakephp 3.8

“src/Controller/Component” in this folder I’m created a “CustomComponent.php”.
How can i access Session in Component?

Got this error “Call to undefined method App\Controller\Component\CustomComponent::getRequest()”,
when try to “echo $this->getRequest()->getSession()->read(‘key’);”

$this->getController()->getRequest()->... See Sessions - 4.x.

1 Like

I’m using cakephp 3.8

got this error

Call to a member function getController() on null

Component code


namespace App\Controller\Component;

use Cake\Controller\Component;
use Cake\Mailer\Email;
use Cake\Filesystem\Folder;
use Cake\Filesystem\File;
use Cake\ORM\TableRegistry;
use Cake\Http\ServerRequest;

class CustomComponent extends Component {

    function __construct($prompt = null) {
 public function sessRead() {        


Please let me know where is the issue

Thanks issue solved

after remove " ```