I am trying to write code based on MVC pattern. Job is to create task & its child task from some input and then generate hierarchy tree/array of parent child tasks. But I face a problem when i try to generate some html based views on that task array. I notice that the model object needs to access the view's methods!
Note: Please ignore any syntax error, it is just to give a problem idea
Model Class
class TaskModel{
private $data;
public TaskModel taskChilds[] = array();
}
View Class
class TaskView{
private $model;
public function __construct($model) {
$this->model = $model;
}
public function showTaskHtml($data) {
// NOT possible because each $data belongs to its corresponding $model
return "<div>$this->$data</div>";
}
public function showChild() {
foreach($this->$taskModel->taskChilds as $child ){
// NOT possible $child is model & the function belongs to view
echo $child->showTaskHtml($data);
}
}
}
Please help me. Give me some code guide line. I am new at MVC