The best way or the approach being used in MVC is to keep your programming logic in the controller, do the database related stuff in the model and format the layout in the view. In your case you should call the $user->getDetails(); in the controller and then pass the result in the view then loop it to output the data, i.e.
In the controller you can populate a variable with $user->getDetails()
$user_details=$user->getDetails();
Then pass $user_details to the view when you load it and in the view loop it
foreach( $user_details as $row ){
echo $row->id;
echo $row->name;
}
If the result is an array of arrays instead of an array of objects then you can use as follows
foreach( $user_details as $row ){
echo $row['d'];
echo $row['name'];
}
Update :
- The model is responsible to manage the data; it stores and retrieves entities used by an application, usually from a database, and contains the logic implemented by the application.
- The view (presentation) is responsible to display the data provided by the model in a specific format. It has a similar usage with the template modules present in some popular web applications, like wordpress, joomla, …
- The controller handles the model and view layers to work together. The controller receives a request from the client, invoke the model to perform the requested operations and send the data to the View. The view format the data to be presented to the user, in a web application as an html output.
Reference: Model View Controller(MVC) in PHP and This.