Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access caller model from behavior in cakephp 3?

I need caller model in my behavior to find and save data. How can I do something like this.

class MyBehavior extends Behavior {
    public function func() {
        $entities = $this->find()->all();
    }
like image 504
anghazi ghermezi Avatar asked Mar 16 '23 23:03

anghazi ghermezi


1 Answers

The table instance a behavior is attached to, is being passed to the constructor, and assigned to the $_table property.

public function func() {
    $entities = $this->_table->find()->all();
}

See also API > Cake\ORM\Behaviour::$_table

like image 164
ndm Avatar answered Mar 23 '23 13:03

ndm