Understanding MVC Views in PHP

后端 未结 7 756
生来不讨喜
生来不讨喜 2020-11-22 10:45

I have to seem problems grasping the concept of Views in MVC, they are, according to what I\'ve read, the layer that manages the presentation in the aplication, but many of

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 11:21

    You are supposed to pass a method in the view class everything it needs to build a view independent of the output format. Most developers will use some sort of templating engine to build the bulk of the page then fill in the body with request specific information. There are so many ways you can go about doing this. It is also good to have an abstract view class that defines helper methods for common elements like forms and inputs.

    This layer is abstracted so that the logic of your application doesn't have to change if you decide to change the design or output format in any way.

    Edit: Each module represented by an MVC set would have its own view that has a collection of methods responsible for sending your output the the browser. There are many ways you can go but here is one example:

    class testModule_view extends viewAbstract {
        public function showTestData($title, $subtitle, $data) {
            $XHTML = '

    ' . $title . '

    ' . '

    ' . $subtitle . '

    ' . parent::data2table($data); parent::outputToBrowser(DEFAULT_TEMPLATE, $XHTML); } }

    This is just a quick example to give you an idea of what a simple view method might look like.

提交回复
热议问题