Didn't work. I still do not understand what would make cake decide to add rows anytime you save data and read data in a controller.
On Feb 18, 10:11 pm, brian <[email protected]> wrote: > This should work > > functionview($id = null) { > if (!$id) { > $this->Session->setFlash(__('Invalid Item.', true)); > $this->redirect(array('action'=>'index')); > } > > $this->Item->recursive = 2; > $item = $this->Item->read(null, $id) > $this->Item->saveField('views', $item['Item']['views'] > + 1, false); > $this->set(compact('item')); > } > > > > On Wed, Feb 18, 2009 at 8:34 PM, NineBlindEyes <[email protected]> > wrote: > > > Ok so here is my problem. I have to have a record of how many times a > > user views a page. I simply want to add 1 to theviewevery time the > >viewpage for the item is loaded. It seems to be updating the views > > correctly, but it also adds to new rows in the database. > > > Here is my code: > > > functionview($id = null) { > > if (!$id) { > > $this->Session->setFlash(__('Invalid Item.', true)); > > $this->redirect(array('action'=>'index')); > > } > > > //Add 1 toview > > $this->Item->recursive = -1; > > $item = $this->Item->read(null, $id); > > $viewnum = $item['Item']['views']+1; > > $this->data['Item'] = array('id'=>$id,'views'=>$viewnum); > > > //Save newview#s > > $this->Item->save($this->data,false,array('views')); > > > $this->Item->recursive = 2; > > $this->set('item', $this->Item->read(null, $id)); > > } --~--~---------~--~----~------------~-------~--~----~ 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] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
