[eluser]animatora[/eluser]
[quote author="WanWizard" date="1332852296"]No.
And certainly not this kind of calls, which technically might be a model call, but it is a Datamapper call.
For me, the correct way is:
- the controller does the model calls relevant to the controller method task
- model calls are functional, usually custom methods, and not low-level (Datamapper) calls
- the controller hands the data to the presenter
- the presenter fetches all ancillary data needed for the view, but not relevant for the controller process
- the presenter passes the data to the view in a simple and easy to use way
Given your code as an example, my model would contain a method called "get_obj_names($var = null)" which would return either an array of names, or an array of objects, that could be passed on. I would not use code like that in a controller, and certainly not in a view.[/quote]
WanWizard, thanks for your answer, it makes more sense now. I think I didnt make myself clear about the type of calls I make. Saying model class I meant DataMapper calls. For example if I have a user class, and each user has many cars what is the best way to get all users and their cars. In my controller I would have:
Code:
$u = new User();
$data['users'] = $u->get();
and inside my view how to print all users with their cars.
Code:
foreach($users as $user)
echo $user->name." has ".print_r($user->car->get());
What is the correct way to get all the cars for each user. In the datamapper manual all examples are echoing data, there is no view example ?
PS. Sorry for not making myself clear in my first post, I will try to avoid it in future.
Regards, Agop