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

pj($this->getController()->getRequest());
got this error

Call to a member function getController() on null

Component code

<?php

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() {        
        pj($this->getController()->getRequest());      
        exit;
    }

}

Please let me know where is the issue

Thanks issue solved

after remove " ```
__construct