Integrating legacy Ajax script in CakePHP
- by octavian
Hi,
I have a legacy script that I would like to integrate in a cakephp app. The script makes use of $_POST and such and since I'm quite a noob I would need some help for the integration.
Here is how the script looks like:
THE JAVASCRIPT:
prototype.js
builder.js (these two are from the prototype fw)
lib.js (makes a ajax requests to remote.php)
THE PHP
remote.php (contains FastJSON class and $_POST vars)
if ($_POST['cmd'] == 'SAVETEAM' && $_POST['info'])
{
$INFO = json_decode(str_replace('\"', '"', $_POST['info']));
$nr = 1;
$SORT = array($INFO->GK, $INFO->DEF, $INFO->MID, $INFO->FOR, $INFO->RZ);
foreach ($SORT as $STD)
foreach ($STD as $v) mysql_query("UPDATE players_teams SET fieldposition = ".$nr++." WHERE player_id = {$v->player_id} AND team_id = {$v->team_id}") or die(mysql_error());
// CAPTAION
mysql_query("UPDATE `teams` SET captain = '{$_POST['captain']}' WHERE `user_id` = {$_POST['userid']}") or die(mysql_error());
}
transfers.php (containts the form that uses the javascript and link to the JS)
I have really no idea how to structure the files and calls in cakephp. Currently I have "Undefined index: cmd [APP/vendors/remote.php, line 230]" errors since I use $_POST['cmd'] (I placed remote.php in Vendors and included it, the JS was just included old fashion way, as a link and appears in the source code). How can I make this work? I'm sorry but I'm not familiar with AJAX and Cake... If you want a full look at the code, here it is: http://octavian.be/thecode.zip
Thank you for reading and helping me out.