How to import vendor files in CakePHP 3x

前端 未结 5 1818
庸人自扰
庸人自扰 2020-12-31 05:37

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

5条回答
  •  星月不相逢
    2020-12-31 06:00

    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 :

    • the vendor folder in cakephp3 is not located in src folder under APP namespace , it is moved to the ROOT folder , by doing you will not be able to load your Facebook class as expected , try it yourself and you will see the result ...
    • By loading a vendor file this is does not automatically load the class name itself , if your vendor lib does not follows the follwing rule as PSR-0 rule : \VENDOR\PACKAGE\TEST.CLASS.PHP and inside the test.class.php there is not a class definition that must be called or imported in your script with a defined namespace keyword in the begining of this script as follows : namespace then the code above will not work

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

提交回复
热议问题