Page 1 of 1

Making an array available to multiple classes.

Posted: Mon Jul 16, 2012 3:35 am
by social_experiment
I am creating three different classes to handle 3 database actions (deleting, editing, adding). I've decided to create a multi-dimensional array with all the required fields of each table, fields of each form needed.

Code: Select all

<?php
 $data = array(
'tracks' => array(
'fields'  => array('control_no', 'track_name', 'track_length',     // will be used to create the form, names & id values
  'alias', 'area', 'province', 'country',
  'contact_name', 'contact_number', 'email_address',
  'web_address', 'track_map', 'directions', 'web_page',
),					
'tooltips' => array('Control number', 'Track name', 'Track length (in meters)',     // tool tips for each field
	'Known as', 'Track area', 'Track province',
	'Track country', 'Contact person', 'Contact number',
	'Email address', 'Web address',	'Track map',
	'Directions', 'Web page',
),
// fields for specific table here
),
// etc
?>
The above element is for data related to the "Tracks" option, the application will work with a few "options", tracks, riders to name just two. I would pass an argument to the object and based on this argument create a form for the specific option or create an edit form or delete the record.

I don't want to re-create this array in each of the classes but i'm not sure how to go about making it available to all 3 classes. Defining it as a constant doesn't work, something about scalar values the error message said so i'm thinking of creating a "base" class from which these 3 classes would extend and thus making the property available to all child classes. Is my approach valid or should i take a different route?

Re: Making an array available to multiple classes.

Posted: Mon Jul 16, 2012 4:15 am
by requinix
I don't get why you want three classes for three actions. And another thing: why does the "delete" class need the full array? As for editing, can you edit all the fields or just a subset?

Re: Making an array available to multiple classes.

Posted: Mon Jul 16, 2012 5:10 am
by social_experiment
requinix wrote:I don't get why you want three classes for three actions. And another thing: why does the "delete" class need the full array? As for editing, can you edit all the fields or just a subset?
My thought is that it would be easier to manage keeping each actions' code seperate. Re. the delete class - touché, i would only need a few fields there. For editing all fields have to be editable