开发者

if an object property is another object, how do i access that object-property's property or method in smarty?

class A
{
  public $property1;
  public $objB;

  public __cons开发者_StackOverflow中文版truct(){
    $this->property1 = 'test';
    $this->objB = new B();
  }
}

class B
{
  public $title;
  public __construct(){
    $this->title = 'title1';
  }

}

so now i do this in the .php file

$a = new A();

in my .tpl i want to display $a->objB->title

how do i do that? i tried

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

i cannot do this in smarty

{$a->objB->title}

i also tried

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

i cannot do this in smarty

{a->objB->title}

OR

{$a->objB->title}

Please advise.


I dont think smarty supports that operation, I had the same problem and solved like this

{assign var='myObject' value=$a->objB}
{$myObject->title}

A little bit long and messy but still a solution.

Another solution might be assigning the title in the php side (but still the same long and messy code)

Or maybe you can define a smarty function that does it for you all the time you need,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜