dplht39359 2018-07-16 10:31
浏览 39

PHP:如何解决这个子数据模型数组调用视图的方法

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本