Symfony 控制器中动作的含义 [英] Meaning of Action in Symfony Controllers

查看:25
本文介绍了Symfony 控制器中动作的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Symfony 框架的新手.我在 Symfony 中启动了简单项目.我在控制器中定义了一个函数,如

I am new in Symfony Framework.I start Simple Project in Symfony.I define a function in Controller like

public function sampleAction()
{

}

这里的Action是什么意思?

What is the meaning of Action here?

推荐答案

将后缀Action"添加到控制器中的那些方法的名称只是一个约定(也在其他框架中,例如 ZF)通过路由直接暴露,使这些动作更好地与其他方法区分开来.

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.

从技术上讲,Action"根本没有任何意义,即:方法不会因为有这个后缀而表现不同.您还可以定义这样的操作方法:

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 不会强制您使用该后缀,但我强烈建议您遵循此约定.

Symfony does not force you to use that suffix, but I would strongly recommend following this convention.

这篇关于Symfony 控制器中动作的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆