从 cakephp 2.x 切换到 3.x 时,如何用对象表示法替换模板中的数组样式表示法

How do I replace array-style notation in templates with object-notation when switching from cakephp 2.x to 3.x

迁移时,有什么方法可以快速替换cakephp的数组表示法2.x

echo $order['id'];

使用cakephp的对象表示法3.x

echo $order->id;

在模板中?

这个正则表达式有效: 找到这个

$order\['(\w+)'\]

并替换为:

$order->

编辑: 以上语法在编辑器 Sublime 2 中有效。在 PHPStorm 中我需要使用此语法来替换:

$offcut->

我认为您可以使用与上面类似的正则表达式,但是 "wider":

\['(.*?)'\](?1)?

并替换为:

->{''}

这对嵌套数组中包含的字段递归工作,并且它可以通过使用大括号处理数字索引上的潜在语法错误。

正则表达式中的示例:https://regexr.com/3k81v