Difference between revisions of "DesignPatternStep7"

From mi-linux
Jump to navigationJump to search
Line 1: Line 1:
 
[[Main Page]] >> [[6CC001|Advanced Web Technologies]] >> [[6CC001 - Workbook|Workbook]] >> [[6CC001 Workshop - week 04|Week 04]] >> Step 7 - Deleting messages
 
[[Main Page]] >> [[6CC001|Advanced Web Technologies]] >> [[6CC001 - Workbook|Workbook]] >> [[6CC001 Workshop - week 04|Week 04]] >> Step 7 - Deleting messages
 +
 +
== Step 7 - Deleting messages ==
 +
 +
Finally, let’s create a new action in charge of message deletion.
 +
 +
Again if you browse the mouse over the “delete this message” links, you will see URLs such as “index.php?cmd=BlogDelete&id=19”
 +
 +
So we need a new Command_BlogDelete class. Here is the code:
 +
 +
<pre>
 +
// Command_BlogDelete.php
 +
 +
//############################################################################
 +
// SearchVenueCommand class
 +
//############################################################################
 +
class Command_BlogDelete extends Command
 +
{
 +
  //############################################################################
 +
  // doExecute
 +
  //############################################################################
 +
  function doExecute(Request $request)
 +
  {
 +
    // Get data from request
 +
    $id = $request->getProperty('id');
 +
   
 +
    // Create manager object
 +
    $manager = new ManagerMessage();   
 +
   
 +
    // Add to database
 +
    $manager->deleteMessage($id);
 +
   
 +
    // Redirect to index
 +
    header("location:index.php");
 +
  }
 +
}
 +
</pre>
 +
 +
Nothing too complicated here...
 +
 +
=== Checkpoint ===
 +
 +
You should now be able to delete messages.
 +
 +
Note: It is always better practice to ask users to confirm deletion first... but you can do that bit&nbsp;;)

Revision as of 15:46, 12 July 2011

Main Page >> Advanced Web Technologies >> Workbook >> Week 04 >> Step 7 - Deleting messages

Step 7 - Deleting messages

Finally, let’s create a new action in charge of message deletion.

Again if you browse the mouse over the “delete this message” links, you will see URLs such as “index.php?cmd=BlogDelete&id=19”

So we need a new Command_BlogDelete class. Here is the code:

// Command_BlogDelete.php

//############################################################################
// SearchVenueCommand class
//############################################################################
class Command_BlogDelete extends Command
{
  //############################################################################
  // doExecute
  //############################################################################ 
  function doExecute(Request $request)
  {
    // Get data from request
    $id = $request->getProperty('id');
    
    // Create manager object
    $manager = new ManagerMessage();    
    
    // Add to database
    $manager->deleteMessage($id);
    
    // Redirect to index
    header("location:index.php");
  }
}

Nothing too complicated here...

Checkpoint

You should now be able to delete messages.

Note: It is always better practice to ask users to confirm deletion first... but you can do that bit ;)