Jump to content

List of reserved words


OLSA
 Share

Recommended Posts

Hello,

I had a problem with this part of code:

$field = $modules->get("InputfieldSelect");
$field->label = $el['label-children'];
$field->attr('id+name','children'); //=> this line was a problem
$field->attr("wrapClass", "large-4 columns");
$options = array('0','1','2','3','4','5','6','7','8','9','+10');
foreach($options as $k => $v) {
  $field->addOption($k, $v);
}
$form->append($field);

and later in some loop I had a trouble

foreach( $form->children as $f ) {
...
}

Because I am still learning Processwire maybe it would be nice to have some kind of "List of reserved words".

My mistake was that I didn't give importance about "children" in this part: 

$field->attr('id+name','children'); 

because I was thinking: ok it will create select field with id="children" and name="children"

But that was wrong :)

Regards,

Sasa

Link to comment
Share on other sites

  • 7 months later...

Just stumbled upon a failing field name, too.

In PW3 "files" is reserved, as not only those names from LostKobrakai's mentioned array are considered reserved, but everything in $wire too.

https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/Process/ProcessField/ProcessField.module#L1439

and in PW3 there's WireFileTools class which populates $files

  • Like 1
Link to comment
Share on other sites

Using your own two or three character prefix (plus _ or -) to name identifiers can be of help no matter what system we use (css, php, js, etc...). This way it is also easy to tell what belongs to your code and what not. It helps in this issue, but also helps others dealing with your code. Sure, the practice of prefixing is not a bulletproof solution, but it is unlikely that one runs into this issue when sticking to it.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...