|
Hi all, Maybe Let's say I'm trying to create a new record using a form and these are the fields in model Article - id, name, content etc Naturally I'd just go ahead to do a $this->Article->save($this->data) with the form elements 'name' and 'content' in the view. I also have the validate options set in my Article model to require both fields. No problem thus far. Naturally, I call $this->Article->create() before $this->Article->save($this->data). However, assuming I have 3 entries in the database with ids 1,2,3. Even if I call a $this->Article->create() first, i notice if I include a form element with name Article/id, What actually happens is that the id of the record specified in that form element is updated if it exists, created if otherwise. This presents a new kind of nightmare for me, understanding that forms can be modified (hacked is more like it) by my site users. Things I've tried - 1. Calling $this->Article->create($this->data) first 2. Specifying the fieldList with just 'name' and 'content' in the array(); However just as I was about typing this mail, an idea occurred to me. And it works. I created my own app_model.php and placed it in my app dir. Here's an extract of the contents <?php class AppModel extends Model{ function create(&$data=""> { if(count($data)){ if(isset($data[$this->name])){ $data[$this->name]['id']=null; } } parent::create($data); } } ?> Using this, I was able to set id to null to fix the 'problem'. And it works. The only other alternatives I see is to extract manually from $this->data what I want to insert or by always setting $this->data['Article']['id'] to null in my controller and any other controller actions that creates new records. Really awkward stuff.... So the easiest fix is the one in the app/app_model.php . Has anyone experienced/solved this any other way? Cheers Femi TAIWO. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
