简体   繁体   中英

Cakephp Behavior wrong model

I am writing a Behavior

<?php

class LogsBehavior extends ModelBehavior {


        public $Model;

        public function setup(Model $model, $config = array()) {
            $this->Model = $model;
        }

        public function afterSave(Model $Model, $created, array $options = array()) {

            pr($this->Model);
            exit;


        }

}

Ok, so when I check the setup method i have in $model:

Comprovante Object
(...)

When i save the entry and i reach afterSave method the $Model property is

Comprovante Object
    (...)

BUT my $this->Model is:

Cliente Object

It seems the previous object is there not the Comprovante...

Someone can help me?

Comprovante.php

public $actsAs = array('Logs');

You may not use a shared attribute here, for the outlined reason above.

Always provide methods, that get passed to the Model as first param:

public function someMethod(Model $Model, ...) {
    $this->_someMethod($Model, ...);
}

protected function _someMethod(Model $Model, ...) {}

etc

See how current core and (popular!) plugin/userland behaviors do it and embrace their way of doing things.

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