Stephen,

STILL NOT WORKING... :(

Thanks for the reply and suggestion. However the method you suggested
gives me different results.
This is what I ended up using:
[code]

$mySaveId =  $this->Network->id = $nId;
$networkId = $this->Network->save($this->data);

[/code]

Nothing is "saved" (editing record) or even "inserted" (if it is a new
record) I am really not sure what is happening. LIke I was saying it
feels like I am losing the Variable value $nId.  $nId is being passed
by assessing the method "/networks/add_network/<nId>"
So I am really confused! :P Thank you for the corrected method though
of saving record via primary key with Model->id=$val I didn't realize
that was the documented way of doing things.



On Feb 11, 2:46 am, Stephen Speakman <[email protected]>
wrote:
> It's possible your $_SESSION['nId'] is actually overwriting the
> parameter being passed to the controller with 0?
> Assuming you're accessing the method like such: /networks/add_network/<nID>
>
> If you want to avoid creating a new record try:
>
> $this->Network->id = $nId;
> $this->Network->save($this->data);
>
> Kind Regards
>   Stephen
>
> On 11/02/2012 08:44, chris varick wrote:
>
>
>
>
>
>
>
> > I am hoping someone can help me out here. I am pulling my hair out.
> > For some reason when I go to save "edited" information, form a form,
> > it is creating an entire new record in the database instead of just
> > updating the current record at hand.
>
> > I am using variable $nId to reference the record id on _save(); For
> > some reason it is setting the $nId to 0. I do not know what is
> > happening. Any suggestions?
>
> > Take a look at the line that has: $mySaveId = ($nId)?$nId:0; you will
> > see where I attempt to save to the current record.
>
> > [code]
>
> > public function add_network($nId = 0)
> >     {
>
> >     // Capture for Debuging
> >     $_SESSION['nId'] = $nId;
>
> >         if($nId){
> >             $net_info = $this->Network->find('first',
> > array('conditions' =>  array('id' =>  $nId)));
> >             self::set('network', $net_info);
> >             self::set('page_title', "View | Edit Network".
> > $net_info['Network']['network_name']." ID: ".$_SESSION['nId']);
> >         } else {
> >             self::set('network', null);
> >             self::set('page_title', "Add Network");
> >         }
>
> >         $alert = null;
>
> >         if ($this->data['network']) {
> >             if ($this->data['network']['network_name']) {
> >                 $data['network_name'] = addslashes($this-
> >> data['network']['network_name']);
> >                 $data['sub_id'] = addslashes($this->data['network']
> > ['sub_id']);
> >                 $data['active'] = 1;
>
> >                 //Save form data to Networks database.
> >                 //If we are editing a network, then make sure to save
> > data to record ID ($nId)
> >                  $mySaveId = ($nId)?$nId:0;
> >                 $networkId = $this->Network->_save($mySaveId, $data);
>
> >                 if ($networkId == $mySaveId) {
> >                     $alert = "Changes to network: ".
> > $data['network_name']." were saved.";
> >                 } else {
> >                     $alert = "New network: ".$data['network_name']."
> > was added.". " ".$networkId;
> >                 }
> >             }
> >         }
>
> >         switch($this->data['window']['flag']){
> >             case "networks":
> >                 self::redirect("/admin/manage_network");
> >                 break;
>
> >         } // switch
>
> >         self::set('logo', $this->Session->read('logo'));
> >         self::set('wbtitle', $this->Session->read('wbtitle'));
> >         self::set('alert', $alert);
> >         self::set('networkId', isset($networkId)?$networkId:null);
> >     }
>
> > [/code]

-- 
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

Reply via email to