Codeigniter and multiple inheritance

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

/**
 * 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();
    }
  }
}

?>

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);
        }

        //
        // **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;
    }        

Is there a problem with using multiple inheritance in a code player? I am new to PHP and codeigniter.

Thanks for watching.

+3
source share
1

, .

codeigniter, Controller, , CodeIgniter .

CodeIgniter . model.php( /library/ ) if (!defined ...), ManageModel

http://www.askaboutphp.com/50/codeigniter-extending-the-native-model-and-make-it-your-own.html

0

Source: https://habr.com/ru/post/1756613/


All Articles