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>\n";
}
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.
You really shouldn't modify the core, actually you souldn't modify any vendor files at all! If you need custom bake output, then do it the proper way as described in the docs:
Cookbook > Shells, Tasks & Console Tools > Code Generation with Bake > Modify default HTML produced by “baked” templates
That being said, you are using double quotes, hence
$
has a special meaning, to actually echo a$
you have to escape it using\
, ie like this:Which is also what is used in the original bake template. Also, as mentioned in another answer, do not use short open tags!