On 07/08/12 19:29, Luis C wrote:
Hello,
I got a weird issue in CakePHP 2.2.
I have created a plugin, let's call it PluginName, and within
PluginName I have the following:
Controller:
- DogsController
- CatsController
Model
- PluginNameAppModel.php
- Dog.php
- Cat.php
(all models extend the PluginNameAppModel.php)
*
within PluginNameAppModel.php I have a beforeSave() function declared*
public function beforeSave(){
$this->data[$this->alias]['created_by'] = 'someone';
return true;
}
*within DogsController I have the following function:*
...
public $uses=array('PluginName.Dog');
...
public function add(){
if($this->request->is('post')){
$this->Dog->save($this->request->data);
}
}
So, when saving the *Dog* data it should also add the *created_by*
column but is not doing that.
After troubleshooting for a while I noticed that the *PluginName.Dog*
(model) is not being used when I'm doing the saving because I added a
dummy variable to it and then printed *$this->Dog
(print_r($this->Dog))* and didn't see the variable when posting the
data. I'm not sure how the saving actually works and why is it not
using the actual *Dog* model class I created.
I have tried clearing cache but it doesn't work still. Any ideas why?
(The file name convention is correct as well)
Any help would be appreciated.
p.s. if I print the Dog class (*print_r($this->Dog; exit;*) before
the*if($this->request->isPost())* statement when the action loads I do
get to see the dummy variable. The issue is happening when I post
from a form.
--
You received this message because you are subscribed to the Google
Groups "CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
Try removing the line public $uses=array('PluginName.Dog'); from your
controller. It is not actually needed since the plugin will find it's
own models by default.
--
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.