Jump to content

Object Oriented PHP


sudsy1970

Recommended Posts

Hi all,

 

have constructed a blog through some tutorials which will add and delete messages.  I wish to add some form of confirmation  box with a yes/no button before deleting but am not sure where to begin. 

 

Thanks for any help

 

<?php
// 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");
  }
}

?>

Link to comment
https://forums.phpfreaks.com/topic/216807-object-oriented-php/
Share on other sites

Why you used the Command pattern in a web environment to handle your requests is beyond me, MVC is much better suited.

 

I wish to add some form of confirmation  box with a yes/no button before deleting but am not sure where to begin.

 

Well this is application logic and as such should be handled in the application, that is in your Controller (or in your case the Command). It could be something like:

 

function doExecute(DeleteRequest $request) {
    if($request->isConfirmed()) {
        ..
    }
}

Link to comment
https://forums.phpfreaks.com/topic/216807-object-oriented-php/#findComment-1126335
Share on other sites

Cheers for that,  this was just the way we were required to code it.

 

so i am guessing that the yes/no buttons will be generated in the views/index.php and the result POST'd back?

 

Yup. It should be noted that views are only present in a Model-View-Controller (MVC) architecture, so why you are required to mix patterns is also beyond me. Is this for class?

Link to comment
https://forums.phpfreaks.com/topic/216807-object-oriented-php/#findComment-1126357
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.