Jump to content

OO PHP task - How do I structure this?


brownpaperbag88

Recommended Posts

Hello everyone,

 

I have this OO Php test I have to do at Uni,

 

I understand the principles of PHP, but I am not sure which classes to use for this task and how to structure it.

 

Also, I cannot use a database, so where can I store the data for the family members?

 

Please see attached file. Any help getting started with this would be much appreciated.

 

Many thanks.

mytest.pdf

Link to comment
Share on other sites

Regarding the data, it doesn't state if the data needs to persist across sessions. You could just create an associative array (or arrays) with the starting state of all the data. Then on the first page load check to see if that data exists in the session. If not, load the initial data. Then on each subsequent page load use the session data. Then, whatever functionality you have will manipulate the session data. If you closed your browser and go back, you would start with the initial seed data. This is a good approach for an activity such as this for several reasons. You can create specific use cases that start with the initial data. As you test, if a problem is found you can modify the code and start the user cases over from the beginning. If you were to use a database you would likely need to reset it to default data anyway.

 

As for the classes to you - that is up to you. How it should ideally be set up for this exercise would likely be predicated on any lessons you've already had in the class as lessons are typically designed to build upon the previous lessons.

Link to comment
Share on other sites

Thanks for your reply. 

 

Can I have an index.php file, generate some data at the top in an assoc array, and the create the $api object and parse the data into $api->getHeritageByName()?

 

Also, could you perhaps tell me how YOU would structure the classes? I am super lost with it.

 

Many thanks.

Link to comment
Share on other sites

I would create an index.php file that is used for all the requests. That file would have something like this at the top

 

 

session_start();
 
//Check if family data is already set in session
if(!isset($_SESSION['family']))
{
    //Set the default data
    include('setDefaultData.php');
}

 

The setDefaultData.php page would have the initial data to set in the session. Something like this

 

$family = array(
    //Include all the associative array data to set for the default
);
 
$_SESSION['family'] = $family;

 

As for how I would do it, I am the wrong person to ask. I don't have a formal education in programming and your instructor is looking for the use of specific design patterns.

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.