duanhao1004 2016-11-01 20:25
浏览 107

CakePHP 2.x - 烘焙视图时出现语法错误。 解析错误:语法错误,意外'$ this'(T_VARIABLE),期待标识符(T_STRING)[重复]

This question already has an answer here:

When attempting to bake views, I consistently get stopped with syntax errors as follows:

Parse error: syntax error, unexpected '$this' (T_VARIABLE), expecting identifier (T_STRING) in /vagrant/lib/Cake/Console/Templates/default/views/index.ctp on line 27

The context for the code causing the error here doesn't seem problematic to me.

<?
foreach ($fields as $field):
  if (!in_array($field, array('created', 'body', 'description', 'position', 'slug'))) {
    echo "\t\t<th><?php echo $this->Paginator->sort('{$field}'); ?></th>
";
  }
endforeach;
?>

It seems to have problems because it is trying to interpret the code it should generate in the string as code it should run, and thus thinks the string '$this->Paginator->sort(...)' is an object variable calling a function, and so on.

I am running PHP 5.3.37-1 on Ubuntu Trusty x64 on a Vagrant box.

</div>
  • 写回答

2条回答 默认 最新

  • dongpao1918 2016-11-01 20:38
    关注

    Don't use short tags: <?

    Use <?php to open a PHP script and use <?= to echo when out of PHP.

    As others are saying it is a simple syntax error. If you have trouble seeing syntax errors, or understanding what your logs are telling you, you may want to consider using an IDE that would help highlight these mistakes.

    <?php 
    foreach ($fields as $field) {
        if (!in_array($field, array('created', 'body', 'description', 'position', 'slug'))) {
            echo "\t\t<th>" .  $this->Paginator->sort($field) . "</th>
    ";
        }
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器