Archive for the ‘vendor’ tag
Switching to App::import() may cause problems
Some time ago importing 3rd party libraries through vendor() method became deprecated and now usage of App::import(’Vendor’, ‘…’) is suggested. I decided to walk through my application files and switch to new version. It was not that easy however… In my app I use Swift Mailer library for sending e-mails.
// I changed this... vendor('Swiftlib/Swift/Connection/SMTP'); // to this... App::import('Vendor', 'Swiftlib/Swift/Connection/SMTP');
It didn’t work, because Cake’s Inflector translated the path to swiftlib/swift/connection/s_m_t_p.php. Of course such file does not exist. Changing vendor’s file names wouldn’t be a good idea. After checking the API I found that App::import() also takes $file parameter if you want to explicitly specify which file to include. So the working solution looks like this:
App::import('Vendor', null, true, array(), APP.'vendors/Swiftlib/Swift/Connection/SMTP.php');
Remember that when you use 3rd party libraries and they do not follow Cake’s conventions in naming files.
