Need Help: A variable is losing value
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home