Search code examples
phpcakephpcakephp-2.0vendor

Where is the correct place to put vendor files in Cakephp 2.X?


I've taken over an old CakePHP 2.X website and have no prior experience with CakePHP so please forgive me if this is a stupid question.

I was looking at making some changes to some vendor files and noticed that we appear to have multiple copies of various files (which are, for the most part, identical) in 2 different places:

  • app/webroot/api/vendor/API/lib/
  • vendors/API/lib/

Additionally I noticed there are several other vendor directories in various other places.

I am using App::import('Vendor', 'example', array('file' => 'API/lib/example.php')); to load the scripts in question.

Could someone please explain to me what the best practices are regarding file structure relating to vendor files? Additionally, am I safe to delete the duplicate copy of all the files? How does CakePHP know which copy to load?

Edit:

I have come to the conclusion that the files are being loaded from vendors/API/lib/ rather than app/webroot/api/vendor/API/lib/, is it possible that the files in the latter location are redundant? I cannot seem to find any references to them.


Solution

  • Coming back a few years later with a little more experience, I feel like I can answer this question better and hopefully help others.

    There are only 2 vendor folders in a standard CakePHP 2.0 implementation: /vendors and /app/Vendor (Note the difference in case and plurality). The one I found in /app/webroot and any other vendor folders you may find are not associated with cakePHP.

    The reason CakePHP has 2 different vendor folders is because you are able to run 2 (or more) CakePHP apps on one copy of the library by creating a second app folder. The /vendors folder is for vendors that are common between all these apps and the /app/Vendor folder is for vendors of that specific app.

    I could not find any best practice information on which one to use by default but I suggest you pick one and stick with it unless you anticipate adding a second app to the installation in the future.

    By using only these 2 folders for vendors you can ensure that standard CakePHP helper methods such as "App::import" and "App::uses" are able to find them.