.Quick问题-我有以下工作语法:
<td tal:define="owner record/owner_id; user user/id; mode php:(owner eq user)?'_edit':'_view'; linkname php:(owner eq user)?'Edit':'View';">
<a href="index.php?-table=${table}&-action=${mode}&id=${record/id}">${linkname}</a>
</td>但我希望能够使用更短的:
<td tal:define="mode php:(record.owner_id eq user.id)?'_edit':'_view';linkname php:(record.owner_id eq user.id)?'Edit':'View';">
<a href="index.php?-table=${table}&-action=${mode}&id=${record/id}">${linkname}</a>
</td>即不必为了php:测试而定义owner和user。
所以我的问题是,我如何在php:上下文中使用错误的点语法?(还有,有没有一种更简单的方式在模板中表达这一点,也就是说,不需要更改模板外部的PHP?
发布于 2011-05-13 04:18:27
只要record和user是对象(类的实例),这种语法就很好用。如果它们是数组,那么您需要:
tal:define="mode php:(record['owner_id'] eq user['id'])当您使用TALES表达式时,PHPTAL会为您找出对象/数组的差异。如果使用php:,则必须注意对象和数组之间的差异。
https://stackoverflow.com/questions/5975869
复制相似问题