我一直在使用Codeigniter来构造一个中等大小的应用程序的前端,并且遇到了一个问题 - 我认为可能是 - PHP中的继承。下面是我想要做的:Codeigniter和多重继承
在遵循MVC架构的过程中,我发现我在模型中复制了很多代码,并决定创建一个可以从其他模型继承的通用模型。够简单。但是,现在,我遇到了常见Model类中定义的一些功能问题。
下面是我在做什么草图:
<?php
/**
* Common Model
*
*/
class DeviceModel extends Model {
function DeviceModel() {
parent::Model();
}
public function getDeviceId($d) { // this is just example code. }
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();
}
}
}
?>
这里是子类:
<?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);
}
//
// **After the refactor, I am receiving Undefined Offsets for this loop.**
//
for ($i=0; $i<sizeof($arrCmds); $i++) {
$html = $this->generateHtml($arrCmds[$i],$did[$i]);
array_push($arrHtml,$html);
}
return $arrHtml;
}
是否有笨使用多重继承的问题吗?我对PHP和codeigniter相当陌生。
感谢您的期待。
我已经在codeigniter中完成了这样的事情,它从来没有引起任何问题。这可能是一个问题与getDeviceInfo的逻辑... 夫妇随机创意的/我的约定调用getDeviceInfo为$ this-> getDeviceInto而不是使用父ref,而不是使用array_push使用arrCmds [] = $ cmds; – 2010-07-26 18:06:51