Loading Vendor Files in CakePHP 2.0

前端 未结 3 1418
花落未央
花落未央 2020-12-23 20:19

I\'m currently upgrading one of our projects to CakePHP 2.0. Unfortunately the \"first line\" of code makes problems, and I can\'t find a solution to that problem.

I

相关标签:
3条回答
  • 2020-12-23 21:10

    Assume you'r vendor file located /app/vendors/facebook/facebook.php here.

    The following line should do the same like App:: import() in the older version of CakePHP

     require_once(ROOT . DS . 'app' . DS .'Vendor' . DS  . 'facebook' . DS . 'src' . DS . 'facebook.php');
    
     $facebookApi = new facebook();
    
    0 讨论(0)
  • 2020-12-23 21:20

    Vendors cannot be loaded using App::uses() in CakePHP, this is because CakePHP cannot expect external libraries to follow the same standards regarding folder and file naming. You can still use App::import('Vendor', ...) as you did in version 1.3 of the framework.

    Now, using App::import() for vendors is kind of silly, if you think about it. It is just an expensive, verbose and very silly wrapper for require_once().

    In 2.0, we actually encourage people to use require or require_once for their Vendor libraries. You can get the location of the Vendor folder using App::path('Vendor') or just APP . 'Vendor' . DS.

    0 讨论(0)
  • 2020-12-23 21:22

    Cake documentation suggest using App::uses() including-files-with-app-import

    However, it also states if you have a non-stanard plugin to use App::Import()

    App::import('Vendor', 'phpQuery', array('file' => 'bariew/phpquery/phpQuery/phpQuery.php'));
    
    0 讨论(0)
提交回复
热议问题