Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Objekt gibt ein Objekt zurück

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
famjaco
Smarty n00b


Joined: 24 Jul 2005
Posts: 4

PostPosted: Sun Jul 24, 2005 3:07 pm    Post subject: Objekt gibt ein Objekt zurück Reply with quote

Hallo,
ich habe folgendes Problem und habe bisher keine brauchbare lösung gefunden.

ich assign von php ein Array voll mit Objekten ins template.
dort laufe ich mit foreach das array durch und lasse mir die werte der objekte anzeigen. dafür habe ich bei den objekten get_ methoden geschrieben. eine der get_methoden gibt allerdings kein string sondern wiederum ein objekt zurück. wenn ich jetzt auf die get_methoden dieses objekts zugreifen will bekomme ich ein fehler.

mal vereinfacht eine syntaktische darstellung:

class User{
private $name;

public get_name(){
return $this->name;
}
}

class NewsEintrag {
private $titel;
private $owner;

public get_titel(){
return $this-tiel;
}

public get_owner(){
return new User($this->owner);
}
}

im template steht:

{foreach from=$newsEinträge item=eintrag}
{$eintrag->get_titel()}
{$eintrag->get_owner()->get_name()}
{/foreach}

Das rot markierte bringt immer einen fehler. kann mir da jemand helfen wie ich das machen kann.

ps. tut mir leid wegen dem unschönen code, aber ich check das nicht wie man das macht das er so schön dargestellt wird.
Back to top
View user's profile Send private message
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Sun Jul 24, 2005 5:25 pm    Post subject: Reply with quote

Hi,

du musst zuerst "$eintrag->get_owner()" nochmal in eine "zwischenvariable" speichern.

Gruß,
Markus
Back to top
View user's profile Send private message
ZakMc
Smarty Pro


Joined: 04 Oct 2004
Posts: 182

PostPosted: Sun Jul 24, 2005 10:24 pm    Post subject: Reply with quote

Code:
{assign var=user value=$eintrag->get_owner()}{$user->get_name()}
Back to top
View user's profile Send private message
famjaco
Smarty n00b


Joined: 24 Jul 2005
Posts: 4

PostPosted: Mon Jul 25, 2005 7:00 am    Post subject: Reply with quote

Super Danke. Jetzt funzt es.
Ist aber schon blöd das smarty das so nicht pakt. na ja so ist auch gut.

gruss
Back to top
View user's profile Send private message
ZakMc
Smarty Pro


Joined: 04 Oct 2004
Posts: 182

PostPosted: Mon Jul 25, 2005 7:18 am    Post subject: Reply with quote

poste das doch mal bei vorschlägen was in smarty 3.0 eingebaut werden soll.
Back to top
View user's profile Send private message
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Mon Jul 25, 2005 1:38 pm    Post subject: Reply with quote

famjaco wrote:
Super Danke. Jetzt funzt es.
Ist aber schon blöd das smarty das so nicht pakt. na ja so ist auch gut.

gruss


Meiner Meinung nach kann das PHP4 von haus aus nicht...
Das geht erst ab PHP5...?

Gruß,
Markus
Back to top
View user's profile Send private message
famjaco
Smarty n00b


Joined: 24 Jul 2005
Posts: 4

PostPosted: Wed Jul 27, 2005 6:29 am    Post subject: Reply with quote

nun ich habe php5 im einsatz. Wink
Back to top
View user's profile Send private message
ZakMc
Smarty Pro


Joined: 04 Oct 2004
Posts: 182

PostPosted: Wed Jul 27, 2005 7:24 am    Post subject: Reply with quote

wie viele wahrscheinlich <-- benutze auch php5 Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP