kennySystemExit
kennySystemExit

Reputation: 329

import custom class in CakePHP

I have 2 custom PHP classes placed in Lib folder. In Controller I need to import following class Custom2, which is inporting class Custom. I can use class Custom2 by instantiation this class and invoking its method inside Controller`s action as following:

<?php
App::import('Lib', 'custom2');
class TestController extends AppController {

    function index() {
         $custom = new Custom2();
         $test = $custom->test();
    }

}

?>

But problem is, that including Custom.php inside Custom2.php is not working trough include_once. I am using this implementation:

Custom2.php:

<?php
include_once 'Custom.php';

class Custom2 {
    public function test() {
         $test = new Custom(); // this is not working               
    }
}
?>
Custom.php:

<?php

class Custom {
    public function test() {
        return "test";
    }
}
?>

Both classes are in the same folder(Lib). What is wrong here?

Upvotes: 1

Views: 2415

Answers (1)

cornelb
cornelb

Reputation: 6066

You can put them in the Vendor folder, as described in the documentation.

App::import('Vendor', 'custom2');

Another option would be to put in the Lib folder

Upvotes: 5

Related Questions