Albert
Albert

Reputation: 1526

Can't import Vendor class into Component in CakePHP 2.5.1

I've been looking at all the related questions of this topic and none of the solutions provided (usually App::import() ) have worked for me, maybe because I have a different configuration, which is the following:

I have a regular cake installation which loads components from an external folder (so outside this installation). That works perfectly, even for the component I'm trying to use now (it works fine until I try to load the Vendor class). This Vendor class I want to have it outside the Cake installation as well (same as with the components). This is how this installation looks:

[root]
.......[shared_resources]
......................................[CakePHP]
........................................................[Components]
..............................................................................MyCustomComponent.php
........................................................[Vendor]
....................................................................[MyVendor]
......................................................................................MyVendor.php
......[MySite]
................... [cakephp typical folder structure]

In my site's bootstrap.php file I have App::build(array('Controller/Component' => array(dirname(ROOT) . '/shared_resources/CakePHP/Component/'))); in order to be able to load that component in any controller, which works fine, any component I put in that folder loads and works without issues.

Now, I'm trying to load the MyVendor class in the MyCustom component, but I can't get it to work, no matter what I try I keep getting class not found errors when trying to instantiate it.

I've tried using php's and Cake's require(), import(), App::import() and App::uses() with all possible combinations of paths (absolute and relative) without any success, puttin them before the declaration of the component class and inside the method that actually uses the vendor class. The last one I've tried is App::import('Vendor', '/absolute/path/to/shared_resources/Vendor/MyVendor/MyVendor.php'); for example.

I've also tried using App::build(array( 'Vendor' => array(dirname(ROOT) . '/shared_resources/CakePHP/Vendor/'))); in the bootstrap file, like with the components.

I don't know what else to try, any help would be much appreciated!!!

Oh, I've check with PHP that the file Vendor class file exists in that path too.

Upvotes: 0

Views: 2461

Answers (1)

Bharat Jain
Bharat Jain

Reputation: 510

According to your folder structure,

To access your MyVendor.php, you should write like this

App::import('Vendor', 'MyVendor', array('file' => 'MyVendor/MyVendor.php'));

For more information, read http://book.cakephp.org/2.0/en/core-utility-libraries/app.html

Upvotes: 1

Related Questions