好吧,这里有一些奇怪的东西让我难倒了大约45分钟......
我有一个自定义.tpl.php文件,我用它来主题节点视图.我有很多PHP已经在这个模板中运行,但今天我有几个我想要移动的CCK字段.
但是,当我添加我的代码片段时,我得到"解析错误:语法错误,意外'['"
<?php print $node->field-account-status[0]['value']; ?>
Run Code Online (Sandbox Code Playgroud)
问题是,这是一个相当常见的片段,应该起作用.这里使用的例子是http://groups.drupal.org/node/25064
这是显示PHP上面和下面的相同片段,两者都工作..为什么这个片段抛出这个错误???
<h2>Service Requests for <?php print $node->title; ?> </h2>
//lines above and below this one are working PHP
<?php print $node->field-account-status[0]['value']; ?>
<?php
$i = 0;
print '<table class="views-account-sr">';
Run Code Online (Sandbox Code Playgroud)
问题是您使用-的是变量名称.-在任何PHP标识符中无效.-是减法运算符.
你可能想要使用_:
<?php print $node->field_account_status[0]['value']; ?>
Run Code Online (Sandbox Code Playgroud)