When working with an MVC framework and querying the database from the controller using the model, what is the best practice?
Should the model provide a very flexible function to allow the controller to query the database? Like a call from the controller as so:
User->find ([
{
or => [
{field => 'name', value => 'john', op => '~' },
{
and => [
{ field => 'organization', value => 'acme', op => '~' },
{ field => 'city', value => 'tokyo', op => '=' }
]
}
],
});
}
Or should the model have a strict API which results in calls like:
User->find_john_or_people_from_acme_in_tokyo();
What is the best way of going about it? Should the SQL be all over the model? Or contained in one queryFactory function? Can you please point me in the right direction? Some OS code would be awesome.
Thanks!