خرید بک لینک

Vote count: 0

I have stated my bespoke MV, I have a simple Model + controller classes and I can't get the var in the model to be recognsed when called by a different function

The controller class is

class StaffController {

protected $module = "staff";

public function __construct()
{
    //include the staff Model
    require_once(MODEL_PATH.$this->module.'.php');
}
public function index() {

    // we store all the posts in a variable
    $staff = Staff::all();

    header('Content-Type: application/json');
    echo json_encode($staff);

}

And $staff = Staff::all(); calls the model class, and its the $list variable that isn't recognized:

class Staff {

public $list = array();

public function __construct() {
      $this->list = [];
}


public static function all() {
  //get all the staff 

  $temp = [];

  $db = Db::getInstance();

  $req = $db->query('SELECT * FROM data ORDER BY ParentID ASC');

  // we create a list of Post objects from the database results
  foreach($req->fetchAll() as $staff) { array_push($temp,$staff);

  self::reorderOrg($temp );

  retu $final;
}


private static function reorderOrg($array, $parent = 0, $depth = 0){
      //reorganise org 

    for($i=0, $ni=count($array); $i < $ni; $i++){
        //check if parent ID same as ID

        if($array[$i]['parentID'] == $parent){

            array_push($this->list ,$array[$i]); //***** no being recognized

            self::reorderOrg($array, $array[$i]['id'], $depth+1);

        }
    }

    retu true;
  }

}

I get the following error Using $this when not in object context in and its to do with the array_push in the model class not liking $this->list. HOw do a set the private var so it can be used within its own class funcitons

asked 3 mins ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 1 ارديبهشت 1395 ساعت: 13:49

صفحه بندی