Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Controller or View as the class name instead of Model.
✗ Incorrect
The Model class handles data and business logic in MVC.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling Model or Controller instead of View.
✗ Incorrect
The Controller calls the View to display data.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names not defined in Model like fetchData or render.
✗ Incorrect
The Model's method to get data is getData().
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping Model and View names or using Controller as a class to instantiate.
✗ Incorrect
The Controller creates a Model to get data and a View to render it.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using display() instead of render(), or swapping Model and View.
✗ Incorrect
The Controller creates a Model to get data, a View to display it, and calls render() on the View.