Making an array available to multiple classes.
Posted: Mon Jul 16, 2012 3:35 am
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.
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?
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
?>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?