I\'m working with CakePHP 3(beta 2) version recently launched. I need to integrate Facebook Login using PHP SDKs and I\'m not clear with importing vendor files in thi
Well you will have to load it yourself if composer is not an option. You can always use the very basic require method and create a new instance of the vendor class yourself. Reference: http://book.cakephp.org/3.0/en/core-libraries/app.html#loading-vendor-files
Use:
//The following line should do the same like App::import() in the older version of cakePHP
require_once(ROOT . 'vendor' . DS . 'Facebook' . DS . 'src' . DS . 'facebook.php');
$facebookApi = new facebook();
the answer provided by Ayman B. does not look like doing the job as expected in the question after i tried it myself , for the following reasons :
To correct the answer you have to do some several steps as follows :
1 - Define in bootstrap.php a new cakephp constant like so : define('VENDOR',ROOT . DS . 'vendor' .DS); as VENDOR constante is removed in cakephp 3.x you can define it yourself 2 - After that , you have to specify the vendor name , the package name and the class name in a vendor constante like : define('_',; and then you can do $facebookApi = new \\();
this is will work for you as expected in the question
If you have issues try to get back to me , i will show you an example of use as described here ...
I also had the same problem with CakePHP 3.0.
Do the installation as instructed using Composer.
Then You have to properly load the plugin in your controller with the use
statement. Like this:
use Ghunti\HighchartsPHP\Highchart;
That will solve the problem of using the plugin.
As of CakePhp 3.x, the recommended code standard is to use require_once without the brackets"()".
require_once(ROOT.'Folder'.DIRECTORY_SEPARATOR.'requiredfile.ph');
becomes
require_once ROOT.'Folder'.DIRECTORY_SEPARATOR.'requiredfile.ph';
https://book.cakephp.org/3.0/en/contributing/cakephp-coding-conventions.html
Hope that helps someone in the future.
In cakephp3 , to add a new vendor library you can follow below steps :
your_project/vendor/
require_once(ROOT . DS . 'vendor' . DS . "my_library_folder" . DS . "my_library_base_class.php")
,this includes the library code file in our code. namespace App\Controller;
use MyLibraryBaseClass;
,
this imports the library code file in our namespace to be used.
create object of loaded class as
$my_obj= new MyLibraryBaseClass();