简体   繁体   中英

How do I call a custom class in the cakephp framework

I am new to cakePHP,

I have write a class in MODEL with name of myClass() and I have one function like func().

CODE:

class myClass(){
    function func(){
        echo "test";
    }

}

But I don't know how to call the "myClass class" and run the function func() in the controller file in the cakePHP framework.

Can any one help me.

Thanks...

require_once(PATH_TO_MODEL.'model.php'); // might not be needed
$myclass = new myClass();
$myclass->func();

Check out http://php.net/manual/en/language.oop5.autoload.php for the comment about require_once not being needed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM