how to assign an object to smarty templates?

Posted by keisimone on Stack Overflow See other posts from Stack Overflow or by keisimone
Published on 2010-03-10T04:45:06Z Indexed on 2010/03/11 5:13 UTC
Read the original article Hit count: 583

Filed under:
|
|
|

i created a model object in PHP

class User {
  public $title;

  public function changeTitle($newTitle){
    $this->title = $newTitle; 
  }
}

How do i expose the property of a User object in smarty just by assigning the object?

I know i can do this

$smarty->assign('title', $user->title);

but my object has something like over 20 plus properties.

Please advise.

EDIT 1

the following didn't work for me.

$smarty->assign('user', $user);

OR

$smarty->register_object('user', $user);

then i try to {$user->title}

nothing came out.

Thank you.

© Stack Overflow or respective owner

Related posts about php

Related posts about smarty