I am new in Symfony Framework.I start Simple Project in Symfony.I define a function in Controller like
public function sampleAction()
{
}
What is the meaning of Action here?
It is simply a convention (also in other frameworks, such as the ZF) to add the suffix “Action” to the name of those methods in controllers which are directly exposed via routes, to make such actions better distinguishable from other methods.
Technically, “Action“ does not have a meaning at all, i.e.: the method does not behave differently because there is this suffix. You could also define an action method like this:
/**
* @Route("/", name="homepage")
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function index()
{
// ...
}
Symfony does not force you to use that suffix, but I would strongly recommend following this convention.
Don't be confused by the naming: a controller class is simply a convenient way to group several controllers/actions together. Typically, the controller class will house several controllers/actions (e.g. updateAction
, deleteAction
, etc).
Refer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With