views:

76

answers:

1

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.

A: 
  1. There's still PHP in CakePHP, $_POST and all the other things are still usable.
  2. The Javascript in the browser doesn't care about Cake at all, it just runs as usual.
    (Unless it retrieves data from the server, which you may have to emulate using Cake.)
  3. The legacy PHP script is quite horrible.
  4. Figure out what it does, document it.
  5. Look at all the variables (var_dump()) in various stages to see what kind of information the script extracts.
  6. Clean it up, fix any errors.
  7. Translate the database operations to Cake.
  8. Ask more specific questions as you come across them.
deceze
The problem is that I'm not familiar with JS. The script was made by some I've paid a few years ago. But the script works, it's just the implementation that fails. Where do I need to place the remote.php? Inside a controller? Or is it a vendor?
octavian
@octavian The Javascript just tries to contact a normal URL, like any browser would do. You can look at the connections being made using something like Firebug. To stick to Cake conventions, put that PHP code in a controller and direct the script to use a URL that'll invoke that controller (you should be able to find the URL in the script). Read the Cake manual about AJAX about how to properly respond to AJAX requests from Cake.
deceze