Well, i wasn't able to make one central update function to cover both
models, but here is what I did just in case some other newbie needs
help:
VIEW/////
//This code is in the view and updates the '$phd_users['PhdUser']
['lastName']' div.
<?php
echo $ajax->editor(
$phd_users['PhdUser']['lastName'],
array(
'controller' => 'PhdUsers',
'action' => 'ajaxupdateUser',
$phd_users['PhdUser']['userID'],
'/lastName'
),
array("okControl" => "false", // Disable the submit button and use
submitOnBlur
"cancelControl" => "false", // Disable the cancelLink (Looks neater)
"submitOnBlur" => "true")); // Enable Submit on Blur
?>
//And this editor updates the 'divSubmitted' div which corresponds to
another model.
<?php
echo $ajax->editor(
'divSubmitted',
array(
'controller' => 'PhdUsers',
'action' => 'ajaxupdateApplication',
$phd_users['PhdApplication']['applicationID'],
'/submitted'
),
array('collection' => array(array('no','no'), array
('yes','yes')))); // Enable Submit on Blur
?>
CONTROLLER///
//These two functions handle the updates for each model
function ajaxupdateUser($userID = null,$sub) {
//Step 1. Update the value in the database
$value = $this->params['form']['value']; //new value to save
$this->PhdUser->id = $userID;
if (!$this->PhdUser->saveField($sub, $value,true)) { // Update
the
field
$this->set('error', true);
}
//Step 2. Set the view variable and render the view.
$this->set('value',$value);
$this->beforeRender();
$this->layout = 'ajax';
}
function ajaxupdateApplication($userID = null,$sub) {
//Step 1. Update the value in the database
$value = $this->params['form']['value']; //new value to save
$this->PhdUser->PhdApplication->id = $userID;
if (!$this->PhdUser->PhdApplication->saveField($sub,
$value,true))
{ // Update the field
$this->set('error', true);
}
//Step 2. Set the view variable and render the view.
$this->set('value',$value);
$this->beforeRender();
$this->layout = 'ajax';
}
Anyway, if you know how the heck I can do this without using two
functions it would be much appreciated. Otherwise this will work.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---