Welcome Guest, Not a member yet? Register   Sign In
Possible to load and use helper function in controller filter?
#1

Hello,

Should it be possible to load and use a custom helper function from within a controller filter?

I want to shortcut creating a Google API client object, the class for which is being auto-loaded by composer. I need the client in most controllers, but in the filter too for auth.

I have "google_client.php" in app/Helpers:

PHP Code:
function init_google_client(){
    $client = new \Google_Client();
    $client->setAuthConfigROOTPATH 'xxxx.json' );

    [...] etc.

    $client->setRedirectUribase_url() );
    $client->setAccessType('offline');        // offline access
    
    
return $client;


Then in the before filter:
PHP Code:
helper('google_client');
$client init_google_client(); 

I get an undefined error on the init function from this.

Alternatively, is there a better way to pass an object variable from a filter into subsequent controllers? The client object cannot be serialized into the SESSION array.

Thanks for help!
Evan
Reply


Messages In This Thread
Possible to load and use helper function in controller filter? - by evansharp - 12-31-2020, 02:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB