What are the potential pitfalls of allowing a model to manipulate data in a controller in PHP?
Allowing a model to manipulate data in a controller can lead to violating the separation of concerns principle, making the code harder to maintain and test. To solve this issue, it is better to keep data manipulation logic within the model layer, where it belongs.
// Controller
$data = $model->getData();
$manipulatedData = $model->manipulateData($data);
```
```php
// Model
public function getData() {
// retrieve data from database or other source
return $data;
}
public function manipulateData($data) {
// manipulate data here
return $manipulatedData;
}