Symfony2 Create Models
Reading Symfony documentation I did not see that talking about Models.
The first thought I thought: I do not want to mix business logic
I dont want DQL in my controller actions. What about MVC than.
My idea is next:
Create new directory in bundle with name Models
Set __ namespace __ for that model and ( use ) attach the necessary
Doctrine class
In my Model class i put DQL logic connected with Entity
Next in controller use current Model.
Just simple controller action whitout mixing DQL in controller
use Company\Bundle\Models\MyModel;
public function getRecentMembersAction($max = 3)
{
$model = new Model() // get model
$list = $model->getRecentMembers($max); // DQL
// Render
return $this->render('CompanyBundle:Controller.index.html.twig',
array('list'=>$list);
}
My question is whether this is a good idea and good practice?
No comments:
Post a Comment