Search code examples
cakephpcakephp-3.x

How to call a controller method from an action


I'm new in CakepHP and I want to use a method (that returns a value) in an action in CakePHP 3. Sort of like this:

public function specify(){
       if(isObject1){
     // do something}
 }
private isObject1($objname){
 return true;
}

What is the right syntax?


Solution

  • CakePHP is PHP

    The way to call a method from another method of the same class is the same as with any php project using objects - by using $this:

    public function specify() {
        $something = 'define this';
        if($this->isObject1($something)) {
            // do something
        }
    }
    
    private function isObject1($objname) {
         return true;
    }
    

    There's more info on how to use objects in The PHP manual.