Jump to content

Recommended Posts

Posted

I have a plugin class and I want to check on Appcontroller.structure event if a client is currently logged in. But

 $this->Session->read("blesta_client_id");

returns null. This is my current code right now

<?php
class OverridesPlugin extends Plugin {
    
    private $Record;

    public function __construct() {
        $this->Record = new Record();
        $this->loadConfig(dirname(__FILE__) . DS . "config.json");
    }

    public function install($plugin_id) {
    
    }

    public function getEvents() {
        return array(
            array(
                'event' => "Appcontroller.preAction",
                'callback' => ["this", "preAction"]
            ),
            array(
                'event' => "Appcontroller.structure",
                'callback' => ["this", "structure"]
            ),
        );
    }

    public function preAction($event){
        Loader::loadModels($this, ['Overrides.OverridesSettings']);
    }

    public function structure($event){

        
       $logged_in_client = $this->Session->read("blesta_client_id");
        $url_details = $event->getParams();
        echo '<pre>'.var_export($logged_in_client,true).'</pre>';
        exit(1);

    }

}

Can you tell me what is the right way to check the client sessions in a plugin class?

 

Thank you

Posted

Are you saying that calling the read() method returns null, or $this->Session is null? Because it looks like $this->Session is null because it's not loaded anywhere. Your Plugin class is not a controller, so it does not inherit the Session object from AppController.

Loader::loadComponents($this, ['Session']);
$this->Session->read('blesta_client_id');

Depending on what you're trying to do, you may want to also consider the fact that staff can log in as a client, so it may not really be the client that's logged in.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...