anghazi ghermezi
anghazi ghermezi

Reputation: 461

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();
    }

Upvotes: 4

Views: 2642

Answers (1)

ndm
ndm

Reputation: 60463

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

Upvotes: 7

Related Questions