CodeIgniter Forums
Call to a member function load() on a non-object when autoloading config files at CI3 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Call to a member function load() on a non-object when autoloading config files at CI3 (/showthread.php?tid=61238)



Call to a member function load() on a non-object when autoloading config files at CI3 - reynierpm - 04-02-2015

I'm working in a small project with CI 3.0. I have set up `/application/config/autoload.php` for autoload app config file as follow:

PHP Code:
$autoload['config'] = array('myappcfg'); 

Then at controller constructor I'm doing the following:
PHP Code:
   protected $facebookSession;

 
   public function __construct()
 
   {
 
       $this->facebookSession FacebookSession::newAppSession(
 
           $this->config->item'facebook_app_id' ),
 
           $this->config->item'facebook_app_secret' )
 
       );
 
   
But I'm getting this notice:
Code:
A PHP Error was encountered Severity: Notice Message: Undefined
property: ShareFacebook::$config Filename:
controllers/ShareFacebook.php Line Number: 16

   Backtrace:
       File: /var/www/html/dts/myapp/application/controllers/ShareFacebook.php
           Line: 16
           Function: _error_handler
   
           File: /var/www/html/dts/myapp/index.php
           Line: 292
           Function: require_once
   
       Fatal error: Call to a member function load() on a non-object in /var/www/html/dts/myapp/application/controllers/ShareFacebook.php on line 16
Can any tell me what I'm doing wrong? Why I can't access `$this->config` at controller if config file is autoloaded?


RE: Call to a member function load() on a non-object when autoloading config files - silentium - 04-03-2015

Of the code you embed, which line is line 16? Can you post the full controller?

On another note, I remember I struggled a lot a year ago when Facebook released the new v4 of the Facebook SDK. And to get it to work with CI.

Since then I have used it a few time and today I made my own built library available in my github account. I hope it will be used or at least help others to figure out how integrate the Facebook SDK with CodeIgniter.

https://github.com/darkwhispering/facebook-sdk-v4-codeigniter


RE: Call to a member function load() on a non-object when autoloading config files at CI3 - Avenirer - 04-03-2015

Of course it can't access the config method, because $this tells the PHP that it should look for the method inside the FacebookSession class. You should first store the config items inside two variables, and then put those variables inside that static method parameters


RE: Call to a member function load() on a non-object when autoloading config files at CI3 - sv3tli0 - 04-03-2015

Just a note..
in __construct() you should put at 1st line
PHP Code:
parent::__construct(); 

Else you are not preloading parent constructor > https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/Controller.php#L66
and inside it you have some very important things Smile
All classes including config are loaded there..
You can't access it if you haven't call parent construct 1st..


RE: Call to a member function load() on a non-object when autoloading config files at CI3 - reynierpm - 04-03-2015

(04-03-2015, 01:35 AM)silentium Wrote: Of the code you embed, which line is line 16? Can you post the full controller?

On another note, I remember I struggled a lot a year ago when Facebook released the new v4 of the Facebook SDK. And to get it to work with CI.

Since then I have used it a few time and today I made my own built library available in my github account. I hope it will be used or at least help others to figure out how integrate the Facebook SDK with CodeIgniter.

https://github.com/darkwhispering/facebook-sdk-v4-codeigniter

Excellent, I can change to this one easily, can this be installed via composer.json file?


RE: Call to a member function load() on a non-object when autoloading config files at CI3 - reynierpm - 04-03-2015

(04-03-2015, 03:01 AM)sv3tli0 Wrote: Just a note..
in __construct() you should put at 1st line

PHP Code:
parent::__construct(); 

Else you are not preloading parent constructor > https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/Controller.php#L66
and inside it you have some very important things Smile
All classes including config are loaded there..
You can't access it if you haven't call parent construct 1st..

Yes, you're right, that was the problem but now I'm running in a second issue cause I got a blank page and facebook stuff doesn't work


RE: Call to a member function load() on a non-object when autoloading config files at CI3 - silentium - 04-03-2015

(04-03-2015, 07:13 AM)reynierpm Wrote: Excellent, I can change to this one easily, can this be installed via composer.json file?

Composer is the only way to install the Facebook SDK with my library Smile


RE: Call to a member function load() on a non-object when autoloading config files at CI3 - reynierpm - 04-03-2015

Good I have this part done, but when I use some of the code at Example.php I got a blank page, why? Can you help me to get this working? BTW have you a library for Twitter or just this one?


RE: Call to a member function load() on a non-object when autoloading config files at CI3 - silentium - 04-03-2015

Have you checked the log files in /application/logs for any errors? The library log any error that the Facebook SDK throws.

If you don't have any log, make sure the logs folder is writable by the server, and that you have turned logging on in application/config/config.php

Regarding Twitter, I do not have a library for the Twitter API at this time.