【发布时间】:2011-01-25 18:06:06
【问题描述】:
我在 PHP 中创建了一个模型对象
class User {
public $title;
public function changeTitle($newTitle){
$this->title = $newTitle;
}
}
如何仅通过分配对象在 smarty 中公开用户对象的属性?
我知道我能做到
$smarty->assign('title', $user->title);
但我的对象有超过 20 多个属性。
请指教。
编辑 1
以下内容对我不起作用。
$smarty->assign('user', $user);
或
$smarty->register_object('user', $user);
然后我尝试{$user->title}
什么都没出来。
编辑 2
我目前只尝试在 smarty 模板中输出对象的公共属性。对不起,如果我将任何人与该功能混淆了。
谢谢。
【问题讨论】:
标签: php smarty viewmodel variable-assignment