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?
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.
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.
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.