无法在这段Php代码中找到错误

时间:2022-09-12 08:39:52

Im getting T_String error on this code, its saying more accuratly on the 2nd line ($form['com...) and i simply cant see why.

我在这段代码上得到T_String错误,它在第二行更准确地说($ form ['com ...)而我只是不明白为什么。

function _maxlength_comment_type_form_alter(&$form, $form_state, $form_id) {
    $form['comment']['comment_max_length'] = array(
     '#type' => 'select',
     '#title' => t('Maximum comment length'),
     '#default_value' => variable_get('comment_max_length_'. $form['#node_type'] -> type, 160),
     '#options'=> drupal_map_assoc(array(140,160,180,200)),
     '#description' => t('numero maximo de caracteres permitidos.'),
     '#weight' => -1,
     );

Im adding this code to Maxlength drupal module.

我将此代码添加到Maxlength drupal模块。

3 个解决方案

#1


It might be this part:

可能是这部分:

'comment_max_length_'. $form['#node_type'] -> type

Try getting rid of the spaces around the arrow?

试着摆脱箭头周围的空间?


Edit - I don't believe the above is actually a problem with the code, though I'd still recommend removing the spaces as a matter of style, just so it's plainly obvious that you're doing this:

编辑 - 我不相信上面的代码实际上是一个问题,虽然我仍然建议删除空格作为一种风格,只是因此很明显,你这样做:

'comment_max_length_'. ($form['#node_type']->type)

rather than this:

而不是这个:

('comment_max_length_' . $form['#node_type'])

Your code is valid and Works On My PCTM.

您的代码有效且可在我的PCTM上运行。


Another edit:

Make sure that $form['comment'] has been defined as well. Perhaps add this at the start of the function.

确保已定义$ form ['comment']。也许在函数的开头添加它。

if (!isset($form['comment'])) $form['comment'] = array();

#2


Two problems I can see, the one nickf alluded to above, i.e. you shouldn't have a space either side of the arrow:

我可以看到两个问题,上面提到的一个问题,即你不应该在箭头的任何一侧有一个空格:

'comment_max_length_'. $form['#node_type'] -> type

Additionally, this shouldn't have a comma after it (as it's the last item in the array):

另外,它之后不应该有逗号(因为它是数组中的最后一项):

'#weight' => -1,`

#3


How about breaking that huge statement into smaller ones so you can pinpoint the problem better?

如何将这个巨大的声明分解成较小的声明,以便更好地查明问题?

#1


It might be this part:

可能是这部分:

'comment_max_length_'. $form['#node_type'] -> type

Try getting rid of the spaces around the arrow?

试着摆脱箭头周围的空间?


Edit - I don't believe the above is actually a problem with the code, though I'd still recommend removing the spaces as a matter of style, just so it's plainly obvious that you're doing this:

编辑 - 我不相信上面的代码实际上是一个问题,虽然我仍然建议删除空格作为一种风格,只是因此很明显,你这样做:

'comment_max_length_'. ($form['#node_type']->type)

rather than this:

而不是这个:

('comment_max_length_' . $form['#node_type'])

Your code is valid and Works On My PCTM.

您的代码有效且可在我的PCTM上运行。


Another edit:

Make sure that $form['comment'] has been defined as well. Perhaps add this at the start of the function.

确保已定义$ form ['comment']。也许在函数的开头添加它。

if (!isset($form['comment'])) $form['comment'] = array();

#2


Two problems I can see, the one nickf alluded to above, i.e. you shouldn't have a space either side of the arrow:

我可以看到两个问题,上面提到的一个问题,即你不应该在箭头的任何一侧有一个空格:

'comment_max_length_'. $form['#node_type'] -> type

Additionally, this shouldn't have a comma after it (as it's the last item in the array):

另外,它之后不应该有逗号(因为它是数组中的最后一项):

'#weight' => -1,`

#3


How about breaking that huge statement into smaller ones so you can pinpoint the problem better?

如何将这个巨大的声明分解成较小的声明,以便更好地查明问题?