Symfony2 proper use for services

41 Views Asked by At

we are currently in the process of choosing a new framework for our application which is using a heavily customised version of Joomla at the moment. After trying to integrate a few different frameworks into the current system we decided symfony best fits our requirements. The old app uses MVC with the bulk of tasks being done in the model class. We are wanting to keep the model layer so we are setting up a bundle for model/data which will potentially double up as an API. The app will be a separate bundle calling on models from the model bundle.

That's some background on how we are modelling the app. Now we are trying to decide how we should call the models. At the moment we are using services.yml in the app bundle to include the model classes. I have been reading that services should be used for what I would call helper classes which can be used throughout the application. I'm just wondering if anyone with more experience with symfony could shed some light on the decisions we have made and is using services.yml to include our model classes is a good idea or could it be something we may regret in the future. We will be rewriting the app as we slowly port it across and are running old and new side by side.

1

There are 1 best solutions below

2
On

I think you globaly misconcieved what was used for what purpose. Your model is to be stored in your Entity folder, relations beween your entities are handled by Doctrine, but entities are nothing more than Plain Old PHP Objects.

They are then used by the Controller(s). Your logic can then be devided in services, for many good reasons (better testability, readability, maintainability ...). It is those services that use services.yml. Therefor your model has nothing to do with your services.yml file, and they should be kept separate.

Hope this helps.