tarapage Posted August 25, 2010 Share Posted August 25, 2010 I have an application that uses a PHP Library for FreshBooks which I added as a vendor file under the main vendor directory (not under app/vendor). I have a method that will load my vendor files as required. Here is the code: private function __importLib($lib) { # Only import the file when it has not been imported already if (!isset($this->importedLibs->{$lib})) { $file = 'FreshBooks/'.$lib.'.php'; $lib = strtolower($lib); App::import('Vendor', $lib, array('file'=>$file)); # Flag that the library has been imported $this->importedLibs->{$lib} = $file; } # Initialize the connection to Fresbooks if(!isset($this->importedLibs->{'init'})) { $this->__init(); } } private function __init() { FreshBooks_HttpClient::init($this->fb_url, $this->fb_token); $this->importedLibs->{'init'} = true; } Problem It WORKS if I do not have the $uses variable defined in the controller, but as soon as I add a $uses variable, the code stops working... Fatal error: Class 'FreshBooks_HttpClient' not found in /var/www/streetscape123/app/controllers/components/freshbooks.php on line 435 My assumption is that the vendor files were not loaded properly, as it cannot find the call in the vendor file. Very strange, I have no idea why introducing this variable causes this. To make it more confusing, other classes in the same library can be loaded with the $uses being set, but this one in particular fails. The difference here, is that Invoice.php is created based on BaseInvoice.php (and this is what includes the Elements.php file which includes the HttpClient). The other classes include the Elements.php file directly in their definition class (which includes the HttpClient file). Any ideas at all would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/211723-cakephp-appimport-problem-strange-behavior-not-loading-file-with-uses/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.