I am learning Object Oriented Programming and as a tool to aid this I am re-coding my custom CMS, which is already working as intended and was originally developed using standard, procedual, PHP programming.
I have only just started putting “pen to paper” after several days of reading and watching videos about OOP. However I am somewhat confused still at the whole prospect. While the actual concept is fine and I can follow tutorials and examples when it actually comes to writing my own code I get lost very quickly!
Here is my “first” class for my CMS re-code, please provide some comments (constructive please!) and thoughts on this.
Can you see a bad habbit forming already?
Have I missed somthing obvious?
Is there any good elements to this?
<?php
class CMSCore {
var $client_user_name;
var $cms_version;
var $client;
var $options;
function __construct($clientUserName,$cmsVersion,$sqli)
{
$this->client_user_name = $clientUserName;
$this->cms_version = $cmsVersion;
}
function get_client_settings()
{
global $sqli;
$mysqli_query = 'SELECT * FROM `cmsSiteSettings` WHERE `ss_userName`="' . $this->client_user_name . '" LIMIT 1';
$query_result = $sqli->query($mysqli_query);
if($query_result->num_rows == '1')
{
if($r = $query_result->fetch_assoc())
{
$this->client['id'] = $r['ss_id'];
$this->client['options_id'] = $r['so_id'];
$this->client['domain_name'] = $r['ss_domainName'];
$this->client['admin_email'] = $r['ss_adminEmail'];
$this->client['public_email'] = $r['ss_publicEmail'];
return $this->client;
}
else
{
return 'Returned empty array: ' . $this->client;
}
$query_result->close();
}
else
{
return $sqli->error;
}
}
function get_client_options()
{
global $sqli;
$mysqli_query = 'SELECT * FROM `cmsSiteOptions` WHERE `so_id`="' . $this->client_options_id . '" LIMIT 1';
$query_result = $sqli->query($mysqli_query);
if($query_result->num_rows == '1')
{
if($r = $query_result->fetch_row())
{
$this->options = Array();
$this->options['google_analytics'] = $r['so_googleAnalytics'];
$this->options['site_name'] = $r['so_siteName'];
return $this->options;
}
else
{
return 'Returned empty array: ' . $this->options;
}
$query_result->close();
}
else
{
return $sqli->error;
}
}
}
?>
Current usage:
$cmsCore = new CMSCore(CLIENT_USER_NAME,CLIENT_CMS_VERSION,$sqli);
$coreArray = $cmsCore->get_client_settings();
echo $coreArray['domain_name'];
// Produces the expected field value for the database however something feels wrong about how I have done this...
Thank you for your time.
Nutty…