Hi please go through this issue and suggest me

Dani AI

Generated

Short, practical summary tied to the existing answers: is on the right track — CodeIgniter 3 has built-in support for using Composer's autoloader so Composer-installed packages (like the Facebook PHP SDK) are available to controllers and libraries. (codeigniter.com)

Concrete checklist (apply in this order):

  1. Install the SDK from the project root with Composer so that a vendor/autoload.php is generated. (getcomposer.org)
  2. Make sure CodeIgniter actually loads that autoload file (either via CI's composer-autoload option or by requiring the autoload in the front controller/bootstrap). If the vendor folder is placed somewhere other than the project root, point CI to the correct path. (stackoverflow.com)
  3. Create a thin wrapper or initialise the SDK in a controller/library so CI can inject it where needed. Example controller constructor (illustrative only — replace APP_ID/APP_SECRET and Graph version as appropriate):
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

use Facebook\Facebook;

class FbTest extends CI_Controller {
  protected $fb;

  public function __construct() {
    parent::__construct();
    $this->fb = new Facebook([
      'app_id' => 'APP_ID',
      'app_secret' => 'APP_SECRET',
      'default_graph_version' => 'v2.10'
    ]);
  }
}

The Facebook SDK README shows the same pattern (require Composer autoload, then instantiate Facebook\Facebook). (github.com)

Troubleshooting & cautions:

  • Confirm vendor/autoload.php exists (run composer install) and that the path used by CI actually points to it. (getcomposer.org)
  • If composer install fails or the SDK complains about missing extensions, verify PHP extensions (curl, openssl, mbstring, etc.) for both the web SAPI and the CLI. Missing extensions commonly break installs. (stackoverflow.com)
  • Keep app id/secret out of source — store them in CI config or environment variables and never commit them. If errors persist, capture and share the exact error message and the autoload path being used; that will make diagnosis straightforward.

Hi,

by default the composer autoload is set to FALSE. So open /application/config/config.php and replace this:

$config['composer_autoload'] = FALSE;

With:

$config['composer_autoload'] = FCPATH . 'vendor/autoload.php';

FCPATH is defined in the root index.php file, if the vendor directory is at the same level, then it should work fine, otherwise define the absolute path to the autoload file.

Now, I have not tested the Facebook SDK with CI3, so I'm not sure this will solve your issue. If problem persist then show us the error codes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.