HTML 表单命名约定的名称

发布于 2024-08-19 10:17:23 字数 282 浏览 5 评论 0原文

在 Rails 和 CakePHP1.2 中,表单往往包含名称如下的输入元素:

<input name="comment[author]" />

“name”属性中使用的符号是否有正式名称?

同样,在 CakePHP1.1 中,我相信同样的情况会是这样的:

<input name="comment/author" />

同样,“name”属性中使用的符号是否有正式名称?

In Rails and CakePHP1.2, forms tend to include input elements with names like the following:

<input name="comment[author]" />

Is there a formal name for the notation used in the "name" attribute?

Likewise, in CakePHP1.1 I do believe that the same would have looked like this:

<input name="comment/author" />

Again, is there a formal name for the notation used in the "name" attribute?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黯然#的苍凉 2024-08-26 10:17:23

在 Rails 中,这被称为表单微格式(至少对于某些人来说)。许多不同的框架似乎都在第一种格式上进行标准化。我想 CakePHP 已经更新了他们的库以符合该标准。有一个非常深入的解释,但只是有点特定于 Rails。最初的微格式显然来自 PHP。

In Rails, this is referred to as the forms microformat (at least by some). Lots of different frameworks seem to be standardizing on that first format. I'd imagine CakePHP has updated their libraries to conform to that standard. There's an obsessively in-depth explanation available that's only somewhat Rails-specific. The original microformat apparently comes from PHP.

弃爱 2024-08-26 10:17:23

在 cake php 中,命名方案采用多维数组访问格式,尽管我不太确定你会怎么称呼它。多维数组键控?

官方 php 文档 调用它“方括号表示法”

基本上,我不确定 cakephp 有一个具体的名称...这是因为它只是用于键控数组访问的“括号表示法”。

这是来自 cakephp 文档的示例。它说明了 cakephp 中使用方括号表示法命名元素,以及如何使用它来预填充值。

使用 cake php FormHelper 我们创建一个隐藏的 id 字段:

echo $this->Form->hidden('id'):

输出如下:

<!-- data comes from $this->request->data -->
<input name="data[User][id]" id="UserId" type="hidden" />

假设 data[User][id] 持有的值是 10,输入带有UserId 的 ID 值为 10。

in cake php, the naming scheme is in multidimensional array access format, though i'm not really sure what you'd call that. multidimensional array keying?

official php docs call it "square bracket notation"

Basically, I'm not sure that cakephp has a specific name for this... This is because it is simply 'bracket notation' for keyed array access.

Here's an example from the cakephp docs. It illustrates naming elements with bracket notation in cakephp, and how this is used to pre-populate values.

using cake php FormHelper we create a hidden id field:

echo $this->Form->hidden('id'):

this outputs the following:

<!-- data comes from $this->request->data -->
<input name="data[User][id]" id="UserId" type="hidden" />

Assuming that the value held by data[User][id] is 10, the input with an ID of UserId will have a value of 10.

御弟哥哥 2024-08-26 10:17:23

在 Rails 中,分配给表单元素中 name 属性的字符串值会作为 params[] 哈希内的哈希传递到控制器,并按键索引。

<input name="username"/>

将在控制器中显示为 params[:username]

<input name="user[name]"/>

将在控制器中显示为 params[:user][:name]

等等。如果您想了解有关如何生成这些内容以及预期结果的更多信息,请参阅 ActionView 和 ActionController 文档。

这是ActionController 概述的链接,这是一个很好的指南。

In Rails, the string value assigned to the name attribute in a form element is passed to a Controller as a hash inside the params[] hash, indexed by key.

<input name="username"/>

Will show up in the controller as params[:username].

<input name="user[name]"/>

Will show up in the controller as params[:user][:name].

And so on. If you want to read more about how to generate these and what to expect, consult the ActionView and ActionController documentation.

Here is a link to the ActionController overview, which is a great guide.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文