Welcome Guest, Not a member yet? Register   Sign In
Call to a member function load() on a non-object when autoloading config files at CI3
#1

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

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/facebo...odeigniter
Reply
#3

(This post was last modified: 04-03-2015, 02:43 AM by Avenirer.)

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
Reply
#4

(This post was last modified: 04-03-2015, 03:03 AM by sv3tli0.)

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/b...er.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..
Best VPS Hosting : Digital Ocean
Reply
#5

(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/facebo...odeigniter

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

(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/b...er.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
Reply
#7

(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
Reply
#8

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?
Reply
#9

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB