2011-05-12 49 views
0

.Quick的問題 - 我有以下的,工作的語法:我的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}&amp;-action=${mode}&amp;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}&amp;-action=${mode}&amp;id=${record/id}">${linkname}</a> 
</td> 

即不必爲了定義owneruserphp:測試中得到他們。

所以我的問題是,我如何在php:上下文中使用點語法錯誤? (另外,有沒有更簡單的方式來表示這在模板內,即不改變模板外部的PHP?

回答

1

只要recorduser是對象(類的實例),這種語法是好的如果它們是數組話,就需要:

tal:define="mode php:(record['owner_id'] eq user['id']) 

當使用TALES表達式,PHPTAL算出對象/數組差爲你如果使用php:,必須注意的對象和陣列之間的差異