It is even worse now.
Let's say I have a hasAndBelongsToMany association in Dog.php with another table (Model). And then in the Controller I have the following
$this->Dog->find('all');
print_r($this->OtherModel); exit;
Instead of getting an instance of OtherModel and all of the associations and variables in it I get an instance of AppModel. if I move the print_r above the dog->find line I get the correct output. If I remove the association I also get the correct output.
Any ideas why? Anybody...
On Tuesday, August 7, 2012 2:29:13 PM UTC-4, 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 declaredpublic 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 cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
No comments:
Post a Comment