Application Super Heroes (PHP Application Super Arrays)

The super hero of the web application is the super array. An example of one from my CMS is detailed below.

$APP_CONFIG[$tbl_faqs]["id_name"] = "faq_id";
$APP_CONFIG[$tbl_faqs]["question"] = array();
$APP_CONFIG[$tbl_faqs]["question"]["field_name"] = "question";
$APP_CONFIG[$tbl_faqs]["question"]["field_title"] = "Question";
$APP_CONFIG[$tbl_faqs]["question"]["field_type"] = "string";
$APP_CONFIG[$tbl_faqs]["question"]["required"] = "Y";
$APP_CONFIG[$tbl_faqs]["answer"] = array();
$APP_CONFIG[$tbl_faqs]["answer"]["field_name"] = "answer";
$APP_CONFIG[$tbl_faqs]["answer"]["field_title"] = "Answer";
$APP_CONFIG[$tbl_faqs]["answer"]["field_type"] = "string";
$APP_CONFIG[$tbl_faqs]["answer"]["required"] = "Y";
$APP_CONFIG[$tbl_faqs]["ordering"] = array();
$APP_CONFIG[$tbl_faqs]["ordering"]["field_name"] = "ordering";
$APP_CONFIG[$tbl_faqs]["ordering"]["field_title"] = "Ordering";
$APP_CONFIG[$tbl_faqs]["ordering"]["field_type"] = "int";
$APP_CONFIG[$tbl_faqs]["ordering"]["required"] = "N";
$APP_CONFIG[$tbl_faqs]["display"] = array();
$APP_CONFIG[$tbl_faqs]["display"]["field_name"] = "display";
$APP_CONFIG[$tbl_faqs]["display"]["field_title"] = "Display";
$APP_CONFIG[$tbl_faqs]["display"]["field_type"] = "string";
$APP_CONFIG[$tbl_faqs]["display"]["required"] = "Y";
$APP_CONFIG[$tbl_faqs]["timestamp"] = array();
$APP_CONFIG[$tbl_faqs]["timestamp"]["field_name"] = "timestamp";
$APP_CONFIG[$tbl_faqs]["timestamp"]["field_title"] = "Timestamp";
$APP_CONFIG[$tbl_faqs]["timestamp"]["field_type"] = "date";
$APP_CONFIG[$tbl_faqs]["timestamp"]["required"] = "Y";

Benefits of using a global application array in a config file for a site include the following:

  • Underlying schema can change with only one file being affected
  • Ability to dynamically generate all forms
  • One generic function to insert rows
  • One generic function to update rows
  • One generic function to perform validation

Next week: Creating instant forms using the underlying schema.

Post a Comment

Your email is never shared. Required fields are marked *

*
*