Question

I am trying to create a upload plugin. I am keeping all the logic in behavior. This thing was working all fine by yesterday and from no where this strange problem is surfaced.

/*controller code */
debug($this->request->data);
$this->Model->saveAll($this->request->data);

/* outputs
Array
(
   [Ad] => Array
    (
        [s] => 2
        [d] => 2
    )

    [Upload] => Array
    (
        [field] => Upload
        [table] => Ad
        [filename] => Array
            (
                [name] => index.php
                [type] => application/x-php
                [tmp_name] => /tmp/php3MbvRh
                [error] => 0
                [size] => 32
            )

    )

)

 */

I am developing a plugin. In plugins beforeSave() i debug the same data and it shows

public function beforeSave(Model $Model) {
    debug($Model->data);
}

/* outputs
Array
(
    [Upload] => Array
    (
        [1pload] => 
    )

)
*/

Everytime there appears a number for the fields property. Sometimes its 1, 8 and/or 9. :(

  • The plugin is loaded fine from bootstrap.php (CakePlugin::loadAll())
  • The plugin uses uploads table. The model of which is maintained as model.
  • The plugin behavior is properly defined and was working perfectly. NOT NOW
Was it helpful?

Solution

I couldn't figure out the problem. But the debug() in beforeSave() was being executed several times. So, I added in the plugin

if( isset ($this->data['preferred']['data'] )  {

}

For first few passes it is still something similar but on the third or fourth time it does show the data.

So, I have come with a theory that the beforeSave in plugin was being asynchronous to that of model's beforeSave and if i put a check then that would solve the issue. In fact it did.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top