Some PHP Objects

Some PHP Objects

You may have heard the term “object-oriented programming“. This refers to a programmong style that recognizes common situations that arise in a programming application, and utilizes a programming language’s support for “objectivizing” these common situations is such a way that the same code can be used whenever similar situations arise. There are many advantages to this, including writing the code once and reusing it over and over, and debugging it once, and appling maintenance – enhancements, bug fixes, etc., once only.

In Joomla inernal code objects are rife and very complex. Joomla supports a way for sites to define their own object models (which are called classes) and use them over and over with relatively simple PHP calls. You should be familiar with Joomla conventions about object oriented programming at , including the concept of a class definition extending another class.This page will provide references to how this works on the FHA site.

To let Joomla know that your PHP code is going to define and use objects, the following line of code is used:

JLoader::registerPrefix(‘Fha’, JPATH_LIBRARIES . ‘/fhalib’); // Reference link

 Thus tells Joomla that when a new object is instantiated, its class definition will by in the directory /libraries/fhalib/ . A “person” object might be defined like this:

$somebody = new FhaResident($pID);

Note the capitalization in FhaResident. The term “Fha”  is the “prefix” defined in the JLoader::registerPrefix() call. The remainder of the word, “Resident” rells JLoader that within the fhalib subdirectory there is a file called “resident”, and within this file there is a class called “fharesident”, which defines the properties and methods of the $somebody object defined above.

With this introduction, there are at this time a number of useful classes defined in fhalib. these are:

  • FhaDblink – defines a MYSQLI link to the FHA database (never used directly)
  • FhaRunsql – Extends FhaDblink – Runs a MYSQLI database query
  • FhaResidence -Extends FhaRunsql – extracts information about a particular residence
  • FhaResident – Extends FhaResidence – extracts information about an individual
  • FhaBbtopics – Extends FhaRunsql – Returns a list of recent (Bulletin) Board topics 
  • FhaAcymailer – Can create an ACYMailing “newsletter” (email) and send to one or more recipients

 This article lists the properties and methods for each of these classes.