|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Mawi Smarty n00b
Joined: 16 Dec 2004 Posts: 2
|
Posted: Thu Dec 16, 2004 3:41 am Post subject: Verständnissfrage |
|
|
...
Hallo Volks
Ich bin in der Sache Template, ein absoluter Einsteiger. Ja Einsteiger, Newbie hört sich doof an *g* Spaß bei Seite. Ich habe schon gelesen, dass Schleifen vs. Arrays eines der Wohl häufigsten Fragen in diesem Forum sind!? Ich komme mit der Umsetzung in der Templatedatei absolut nicht klar. Nein. Auch nicht mit dem Aufgezeigten Beispiel, des Manuals. Was ich eh ein wenig kurz finde
Vielleicht macht sich ja jemand kurz die Mühe, mir das prinzipiell zu verdeutlichen, an Hand meines Beispiels.
Sei mal angenommen ich habe folgende MySQL - über PHP - Abfrage.
[php:1:646f3211ab]<?php
while( $daten = mysql_fetch_object($result) ) {
$autor[] = array('post_id' => $daten->posters_user_id);
$posting[] = array('reply' => $daten->posters_reply);
}
?>[/php:1:646f3211ab]
1. Frage:
Sollte ich diese 2 Werte über Append, oder Assign übergeben?
Vielleicht so? Versuchsbeispiel:
[php:1:646f3211ab]<?php
$smarty->append('row', $autor);
$smarty->append('row', $posting);
// oder
$smarty->assign('row', $autor);
$smarty->assign('row', $posting);
?>[/php:1:646f3211ab]
2. Frage:
Wie sehe denn meine Template Datei aus?
Code: |
{foreach name=aussen1 item=shows from=$row}
<table>
<tr>
<td class="autor">{$shows.post_id}</td>
<td class="reply">{$shows.reply}</td>
</tr>
</table>
{/foreach}
|
Ich bin IMHO sicher absolut auf dem falschen Dampfer?!
Mein Ziel ist es, meinem Designer zu ermöglichen, dass er selbst den HTML-larischen Aufbau selbst bestimmen kann, indem einfach die Schlüsselwörter positioniert, wie er möchte.
BTW: Ja sorry, aber ich bin im Moment irgendwie damit überfordert. Kann aber auch an der Uhrzeit liegen
... |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Dec 16, 2004 8:48 am Post subject: Re: Verständnissfrage |
|
|
vieles ist da sicher geschmacksache, aber ich würde assign nehmen.
ich baue meine arrays immer erst komplett in php und assigne sie dann:
z.b.:
[php:1:e696a06300]<?php
$rows = array();
while ($row = mysql_fetch_object($result) ) {
$rows[] = array('user_id' => $row->posters_user_id,
'reply' => $row->posters_reply);
}
$smarty->assign('rows', $rows);
?>[/php:1:e696a06300]
und im template dann irgendwie so:
Code: |
{foreach item=row from=$rows}
<table>
<tr>
<td class="autor">{$row.user_id}</td>
<td class="reply">{$row.reply}</td>
</tr>
</table>
{/foreach}
|
was die bezeichner angeht:
meine sind hier sicher nicht optimal, aber deine waren es auch nicht .
sehe zu, dass du gleiche sachen immer gleich nennst (und dass du natürlich niemals verschiedenen sachen gleiche namen gibts).
du hast "user", "author" und "poster" in deinem code, aber irgendwie scheinen die alle mehr oder weniger das gleiche zu bedeuten. ich würde mich hier auf eines der 3 einigen und das dann konsistent in der db, im php und im template benutzen.
nur so als tipp.
HTH
messju |
|
Back to top |
|
Mawi Smarty n00b
Joined: 16 Dec 2004 Posts: 2
|
Posted: Sat Dec 18, 2004 2:27 pm Post subject: |
|
|
Danke für die Antwort
Okay.. Ich hab nun wieder ein Problem ;/
Wieso erhalte ich immer nur den ersten Buchstaben, und sonst nix?
[php:1:7e5aa2b65a]
// sonstiger Code
$select = "SELECT
k.kat_name,
k.kat_id,
k.kat_beschreibung,
k.kat_hidden,
f.foren_beschreibung
FROM
kategorien k
INNER JOIN
foren f
ON
k.kat_id = f.foren_ordnung
ORDER BY
k.kat_hidden DESC,
k.kat_name ASC
";
$result = mysql_query($select) or die (mysql_error());
while($raw = mysql_fetch_array($result)) {
$row[] = $raw['kat_name'];
$row[] = $raw['kat_beschreibung'];
}
array_pop($row);
$smarty->assign("forum", $row);
#
#
### Anzeigen
$smarty->display(INCLUDE_DIR.'templates/'.def_template.'/header.tpl');
$smarty->display(INCLUDE_DIR.'templates/'.def_template.'/forum/forum_index.tpl');
$smarty->display(INCLUDE_DIR.'templates/'.def_template.'/footer.tpl');
[/php:1:7e5aa2b65a]
Code: |
{section name=forum loop=$forum}
<table align="center" width="90%" cellpadding="5" cellspacing="4" bgcolor="#030D4E">
<tr>
<td>
{$forum[forum].kat_name}
</td>
</tr>
<tr>
<td>
{$forum[forum].kat_beschreibung}
</td>
</tr>
<tr>
<td>
{$forum[forum].foren_beschreibung}
</td>
</tr>
</table>
{/section}
|
Ausgabe wäre ca.
M
A
C
D
statt:
Moderation
Administration
Community
Dramen |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Dec 20, 2004 8:32 am Post subject: |
|
|
mach mal {$forum|@debug_print_var} im template oder aktiviere die debug-konsole.
dann wirst du sehen, dass $forum nicht die struktur hat, die du vermutest. |
|
Back to top |
|
|
|
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
|