Hi Cricket, Thanks for the help, much appreciated...
Would option 2 go into the "links controller"....?? I just tried adding the db column, but it didnt show up... but i know why as i changed some code back to how it was, so im sure it should work when i update it...i have updated the DB to include the column "reciprocallink"....Is it the "controller" and the "view" that need updating?? or will i have to update a model as well....?? Thanks again for helping... Brook On Apr 19, 7:47 pm, cricket <[email protected]> wrote: > On Tue, Apr 19, 2011 at 4:11 AM, dvvbrook79 > > <[email protected]> wrote: > > DAM!!...Scrap that last note: > > Just been checking the DB and theres is nothing for the forms, and i > > just thought whilst looking...i dont need to store the "Reciprocal > >Link" i just need it to show up in theemail....Now im really > > confused...PLEASE HELP!! > > If there's no column for reciprocallink in the DB, when you save theLink, > that information will be ignored. You problem is that you're > saving the submitted data, then fetching it from the DB to create a > view var named $link. You're then trying to access reciprocallink from > the $linkvar. But, of course, there being no reciprocallink column in > the DB, $linkwill not contain it. > > So you have two options. > > 1: Create the column in the DB table. The reciprocallink will be > stored and will also appear in $linkfor your view. > > 2: Set a separate view var for reciprocallink. > > $this->set( > 'link', > $this->Link->findById($this->Link->id) > ); > > $this->set( > 'reciprocallink' > $reciprocallink > ); > > view: > > <td><?php echo $reciprocallink; ?></td> > > I think 1 is the simplest solution and makes most sense. If you're > going to storeLinkit may as well include reciprocallink. > > However, it's unclear to me why you're doing an extra find immediately > after saving. Unless you have some need for the ID (it doesn't appear > so) or one or more fields are altered in a beforeSave or afterSave > calback in theLinkmodel, there's no need to call find() after > saving. You could just do something like this: > > function submit() > { > if (!empty($this->data)) > { > // do CAPTCHA validation ... > > $this->Link->create(); > $this->data['Link']['approved'] = 0; > > $this->Link->set($this->data); > > if ($this->Link->validates()) > { > // validation ok, try to save > if ($this->Link->save($this->data)) > { > $this->set( > 'link', > $this->data['Link'] > ); > > // sendemail > } > else > { > // save failed, set flash msg > } > } > else > { > // validation failed, set flash msg > } > } > > $this->set( > 'categories', > $this->Link->getCategories() > ); > > } > > view: > <td><?php echo $link['title']; ?></td> > ... > <td><?php echo $link['description']; ?></td> > ... > <td><?php echo $link['reciprocallink']; ?></td> > > Notice that you don't need to include ['Link'] in the view because > $linkwas set from $this->data['Link'], not $this->data. > > You should also do $this->Link->set($this->data), then perform > validation, setting flash messages as needed. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
