Join Jon Peck for an in-depth discussion in this video The anatomy of a controller, part of Learning Symfony2 for PHP.
- In Symfony, controllers are responsible for…generating a response to a request.…There's a couple different ways of producing response.…One way is to directly return a response object,…but this leads to a very slippery slope of…mixing business logic with presentation.…That's typically a bad thing.…Therefore, whenever possible it's preferable…to render the data with a view.…This separates the logic from the presentation.…Controllers contain what are known as actions,…which are methods within the controller class.…Actions should be atomic as possible,…meaning each action should do only one thing.…
It's perfectly acceptable to perform an action…and redirect to another if another operation is required.…Actions are named after verbs that define a…user behavior, such as list, update, delete, and so forth.…Action names are in lowerCamelCase notation,…so start with a lowercase letter and make sure…that it ends with a suffix Action with a capital A.…To extend on the previous example, the complete name…would be listAction, updateAction and deleteAction.…
- Installing Symfony
- Creating a bundle from the console
- Customizing and generating database tables
- Generating controllers
- Creating, editing, and debugging entities
- Displaying and debugging a form
- Rendering content with templates
Skill Level Intermediate
Q: When trying to access the application, I receive an error stating "This script is only accessible from localhost." How can I get around this restriction?
A: The development front controller and configuration scripts are protected by default to only allow access from the localhost. Refer to the video titled “Exploring the Symfony layout” to see how to disable this security.