Jump to content

OOP - Convert Function to Class


benanamen

Recommended Posts

How would I to convert the following function to a class? What is the proper way to deal with GET and POST in a class since they are globals?

 

My start

class ShowActionMessage
{

}

Function to convert

function show_action_messages()
{
if (isset($_GET['insert']))
{
$action = 'Added';
}

if (isset($_GET['edit']))
{
$action = 'Updated';
}

if (isset($_GET['deleted']))
{
$action = 'Deleted';
}

if (isset($_GET['emailed']))
{
$action = 'Emailed';
}

if (isset($action))
{
?>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="success">Record <?= $action ?></div>
</div>
</div>
<?php
}
}
Edited by benanamen
Link to comment
Share on other sites

This is just for learning OOP. It is not about the function itself really, but how to handle superglobals in a class. The issue actually came up in a login logging class that uses $_SERVER['REMOTE_ADDR'], another superglobal. Several code analyzers (scrutinizer, codacy, code climate ) pointed out a problem with using them in the class. 

 

 

* As far as what the function is for, it is used to display messages to the user after certain actions such as a db record added or deleted

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.