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
#2

I implemented a shared service, which is working so far.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB