I use Codeigniter to create the front end of a moderate-sized application and have run into a problem with - I think - inheritance in PHP. Here is what I am trying to do:
Following the MVC architecture, I found that I duplicated a lot of code in models and decided to create a common model from which other models could be inherited. Simple enough. However, now I am having problems with some functions that are defined in the general class of the model.
Here is a sketch of what I'm doing:
<?php
class DeviceModel extends Model {
function DeviceModel() {
parent::Model();
}
public function getDeviceId($d) {
public function getDeviceInfo($id) {
$selectStmt = "SELECT BLAH, BLAH2 FROM YADDAYADDA...";
$query = $this->db->query($selectStmt, array($id));
if ($query->num_rows() > 0) {
return $query->result();
}
}
}
?>
Here is the subclass:
<?php
require_once('devicemodel.php');
class ManageModel extends DeviceModel {
function ManageModel() {
parent::DeviceModel();
}
function getDropDownList($parkId,$tableName,$userclass) {
$arrCmds = array();
$arrHtml = array();
$deviceInfo = parent::getDeviceInfo($parkId);
$did = parent::getDeviceId($deviceInfo);
foreach ($deviceInfo as $device) {
$cmds = $this->getDeviceCommands($device->dtype,$tableName,$userclass);
array_push($arrCmds,$cmds);
}
for ($i=0; $i<sizeof($arrCmds); $i++) {
$html = $this->generateHtml($arrCmds[$i],$did[$i]);
array_push($arrHtml,$html);
}
return $arrHtml;
}
Is there a problem with using multiple inheritance in a code player? I am new to PHP and codeigniter.
Thanks for watching.
source
share