HTML 表单命名约定的名称
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 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.
在 cake php 中,命名方案采用多维数组访问格式,尽管我不太确定你会怎么称呼它。多维数组键控?
官方 php 文档 调用它“方括号表示法”
基本上,我不确定 cakephp 有一个具体的名称...这是因为它只是用于键控数组访问的“括号表示法”。
这是来自 cakephp 文档的示例。它说明了 cakephp 中使用方括号表示法命名元素,以及如何使用它来预填充值。
使用 cake php FormHelper 我们创建一个隐藏的 id 字段:
输出如下:
假设
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:
this outputs the following:
Assuming that the value held by
data[User][id]
is10
, the input with an ID ofUserId
will have a value of 10.在 Rails 中,分配给表单元素中
name
属性的字符串值会作为params[]
哈希内的哈希传递到控制器,并按键索引。将在控制器中显示为
params[:username]
。将在控制器中显示为
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 theparams[]
hash, indexed by key.Will show up in the controller as
params[:username]
.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.