Handling the Object ID

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:05
    The ships are loading dynamically, but I've got some bad news.
  • 0:10
    We broke our app. Start a battle. Select the Jedi Starfighter as one of the ships,
  • 0:20
    and engage. Huh, so instead of the results we see, "Don't forget to select some ships to battle!"
  • 0:28
    Pretty sure we selected a ship, but the URL has a ?error=missing_data part.
  • 0:38
    Index.php is reading this.
  • 0:42
    It all comes from battle.php, and it happens if we post here but we're missing $ship1Name or $ship2Name—
  • 0:50
    in other words, if we forget to select a ship—but we did select a ship.
  • 0:56
    Somehow these select menus are broken.
  • 1:02
    Check out the code. We're looping over $ships and using key as the option value.
  • 1:09
    In getShips, the key was a nice Unix string. But now it's just the auto-increment index.
Loading ...

Handling the Object ID

Loading...

In the last tutorial we set up our app to fetch the ship objects from the database, but now our app ship select lists are not working properly. To deal with that, in this tutorial, we're going to add a ship ID property to our class and then we will use the ShipLoader class to query for individual ships. Lastly, we will once again need to turn the array that we fetch into an object that our app can use. As an added bonus we'll also update the PHPDoc so we can get autocompleting method names.

Downloads: 
Log in or sign up to download companion files.

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.