我的 PHPTAL 语法有什么问题?
快速问题 - 我有以下工作语法:
<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>
即不必定义 owner
和 user
以获得对他们进行 php:
测试。
所以我的问题是,我如何在 php: 上下文中使用错误的点语法? (另外,是否有一种更简单的方法可以在模板内表达这一点,即无需更改模板外部的 PHP?
.Quick question - I have the following, working syntax:
<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>
but I was expecting to be able to use the shorter:
<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>
i.e. not having to define owner
and user
in order to get at them for the php:
test.
So my question is, how am I using the dot syntax wrong in the php:
context? (also, is there a simpler way to express this WITHIN THE TEMPLATE i.e. without changning the PHP external to the template?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要
record
和user
是对象(类的实例),这种语法就可以。如果它们是数组,那么您需要:当您使用 TALES 表达式时,PHPTAL 会为您计算出对象/数组之间的差异。如果您使用
php:
,则必须注意对象和数组之间的差异。This syntax is fine as long as
record
anduser
are objects (instances of classes). If they are arrays, then you need:When you use TALES expressions, PHPTAL figures out object/array difference for you. If you use
php:
, you have to watch out for differences between objects and arrays.