0
0
PHPprogramming~10 mins

MVC architecture overview in PHP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the Model class in MVC.

PHP
<?php
class [1] {
    public function getData() {
        return "Data from model";
    }
}
?>
Drag options to blanks, or click blank then click option'
AModel
BApp
CView
DController
Attempts:
3 left
💡 Hint
Common Mistakes
Using Controller or View as the class name instead of Model.
2fill in blank
medium

Complete the code to call the View in MVC.

PHP
<?php
class Controller {
    public function show() {
        $view = new [1]();
        $view->render();
    }
}
?>
Drag options to blanks, or click blank then click option'
AController
BModel
CTemplate
DView
Attempts:
3 left
💡 Hint
Common Mistakes
Calling Model or Controller instead of View.
3fill in blank
hard

Fix the error in the Controller method to get data from Model.

PHP
<?php
class Controller {
    public function getData() {
        $model = new Model();
        return $model->[1]();
    }
}
?>
Drag options to blanks, or click blank then click option'
AfetchData
BgetData
Crender
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names not defined in Model like fetchData or render.
4fill in blank
hard

Fill both blanks to create a simple MVC flow: Controller calls Model and then View.

PHP
<?php
class Controller {
    public function display() {
        $model = new [1]();
        $data = $model->getData();
        $view = new [2]();
        $view->render($data);
    }
}
?>
Drag options to blanks, or click blank then click option'
AModel
BController
CView
DTemplate
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping Model and View names or using Controller as a class to instantiate.
5fill in blank
hard

Fill all three blanks to complete the MVC interaction: Controller gets data, passes to View, and View renders.

PHP
<?php
class Controller {
    public function show() {
        $model = new [1]();
        $data = $model->getData();
        $view = new [2]();
        $view->[3]($data);
    }
}
?>
Drag options to blanks, or click blank then click option'
AModel
BView
Crender
Ddisplay
Attempts:
3 left
💡 Hint
Common Mistakes
Using display() instead of render(), or swapping Model and View.