Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of Action in Symfony Controllers

Tags:

php

symfony

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?

like image 784
Karan Avatar asked Dec 07 '15 05:12

Karan


2 Answers

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.

like image 138
BlueM Avatar answered Oct 27 '22 05:10

BlueM


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

like image 1
Sanjuktha Avatar answered Oct 27 '22 05:10

Sanjuktha