For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > July 2004 > Traversing objects from within a template









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Traversing objects from within a template
Tim Lucas

2004-07-07, 8:59 am

I want to pass an object which is a composite of objects to my smarty
template and be able to be access the nested object.

For example:

{$gallery->getPicture()->getTitle()}


A simplified version of my object is as such:

class SVGallery
{
var $_picture;

function SVGallery(&$picture)
{
$this->setPicture($picture);
}

function setPicture(&$picture) { $this->_picture = &$picture; }

function &getPicture() { return $this->_picture; }
}

My php does the following:
$smarty->assign_by_ref('gallery',$oGallery);

The smarty debug output shows the nested objects fine, I just can't
access them using the template syntax.

I've tried assigning the object to a template var and running the
method, but that does not work either.

I've found this same question on the FAQ with no answer:
http://smarty.incutio.com/? page=Sm...p
late-17


Any ideas aside from converting all my objects into nested associative
arrays, which, although it would reduce coupling between model and view,
I don't particularly need in this situation.

-- tim

http://www.toolmantim.com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com