View previous topic :: View next topic |
Author |
Message |
Lariphos Smarty Rookie
Joined: 10 Jul 2017 Posts: 9
|
Posted: Mon Jul 10, 2017 4:52 pm Post subject: Array aus Datenbank mit Variable |
|
|
Hallo zusammen,
derzeit versuche ich einen Text mittels pdo aus meiner Datenbank zu laden und über die Smarty Engine anzuzeigen. Das klappt auch soweit, allerdings befindet sich in diesem Text eine Variable die keinen Wert enthält zu mindestens nicht in diesem Text an einer anderen stelle im code funktioniert die Variable.
Leider hat sowohl die Forensuche als auch die Googlesuche nichts passendes erbracht, daher suche ich nun hier um Rat.
Datenbankabfrage Text
Code: |
<?php
$getLanguage = "SELECT 'key', 'content' FROM 'language' ORDER BY 'id'";
foreach { ($pdo->query($getLanguage) as $row) { $game["language"][$row[0]] = $row[1]; }
?>
|
Datenbankabfrage Versionsnummer
Code: |
<?php
$getGameVersion = "SELECT 'version' FROM 'changelog' ORDER BY 'id' DESC LIMIT 1";
foreach ($pdo->query($getGameVersion) as $gameVersion) {
$game["config"]["version"] = $gameVersion["version"];
}
?>
|
Smarty Template PHP
Code: |
<?php
$tpl = new Smarty;
$tpl->assign($game);
$tpl->display('include/template/outsite/start.tpl'j;
?>
|
Im Template rufe ich dann die Variable {$language.copyrigt} auf. Dort wird dann auch der Text angezeigt, aber wie oben erwähnt befindet sich in dieser Variable die Variable {$config.version} die in dem Text keinen Wert enthält, ruf ich sie aber zur selben zeit an einer anderen stelle im selben Template auf hat sie den Wert den sue haben sollte. Warum also wird er bei dem Text aus der Datenbank nicht auch übernommen?
Last edited by Lariphos on Fri Jul 14, 2017 7:59 am; edited 3 times in total |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Jul 10, 2017 6:35 pm Post subject: Re: Array aus Datenbank mit Variable |
|
|
Lariphos wrote: | "SELECT 'Version'
...
$gameVersion["version"]; |
I see an apparent issue with your code. |
|
Back to top |
|
Lariphos Smarty Rookie
Joined: 10 Jul 2017 Posts: 9
|
Posted: Mon Jul 10, 2017 7:02 pm Post subject: |
|
|
when you mean the ' it's just because i write with my mobile phone it doesn't have the normal symbol ^^ |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Jul 10, 2017 7:18 pm Post subject: |
|
|
No, I did not mean that.
I mean that you are not using right variable names and not using proper error_reporting level to notice it. |
|
Back to top |
|
Lariphos Smarty Rookie
Joined: 10 Jul 2017 Posts: 9
|
Posted: Tue Jul 11, 2017 6:48 am Post subject: |
|
|
AnrDaemon wrote: | No, I did not mean that.
I mean that you are not using right variable names and not using proper error_reporting level to notice it. |
why is that wrong? Because the Big A? That was just a error from the mobile auto correction. I edit the posting and fix this "bug". Error reporting is already on with E_ALL and it doesn't come a error, warning or notice. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Jul 11, 2017 6:24 pm Post subject: |
|
|
Then check each variable before and after assignment. |
|
Back to top |
|
Lariphos Smarty Rookie
Joined: 10 Jul 2017 Posts: 9
|
Posted: Wed Jul 12, 2017 7:35 am Post subject: |
|
|
The problem is the text from sql. When i use each array/variable manually he found it, but he doesn't insert the variable into the variable from the sql. |
|
Back to top |
|
Lariphos Smarty Rookie
Joined: 10 Jul 2017 Posts: 9
|
Posted: Fri Jul 14, 2017 6:10 am Post subject: |
|
|
No idea? Maybe it helps when i upload the script so you can look over it? |
|
Back to top |
|
Grizzly Smarty Pro
Joined: 15 Apr 2011 Posts: 172 Location: Germany
|
Posted: Fri Jul 14, 2017 6:52 am Post subject: |
|
|
Kannst du den Template Inhalt schicken, in dem du auch die zwei stellen aufrufst? |
|
Back to top |
|
Lariphos Smarty Rookie
Joined: 10 Jul 2017 Posts: 9
|
Posted: Fri Jul 14, 2017 7:25 am Post subject: |
|
|
Grizzly wrote: | Kannst du den Template Inhalt schicken, in dem du auch die zwei stellen aufrufst? |
Gern
Code: |
<header>
<h1>{$game.config.gameTitle}</h1>
<h2>{$game.config.gameDescriptionShort}</h2>
<h3>{$game.language.copyright}</h3>
</header>
|
{$game.language.copyright} ist dann der Array der Probleme macht, dort befindet sich folgender Inhalt
Code: |
© 2017 - 2018 • Marcel Geveler • <a href="index.php?location=changelog">{$game.config.version}</a>
|
{$game.config.version} wird dann nicht mit einem Wert gefüllt, obwohl dieser Wert ans Template übergeben wird, da ich in manuell an selber stelle Abfragen kann.
Hab auch schon probiert die Datenbankabfragen in der Reihenfolge zu ändern, da ich erst die Sprache geladen hab und dann die Konfiguration, aber das hat auch nichts geändert. Genau so hab ich versuch das ganze in einem mehrdimensionalen array zu verbinden (daher die geänderten Namen), dass hat aber ebenfalls nichts gebracht ebenso wenig ein auslagern in einzelne Dateien. Anschließend hab ich auch versucht den Array noch mal manuell mittels $tpl->assign einzubinden, aber auch das brachte nicht den gewünschten Effekt. |
|
Back to top |
|
Grizzly Smarty Pro
Joined: 15 Apr 2011 Posts: 172 Location: Germany
|
Posted: Fri Jul 14, 2017 12:27 pm Post subject: |
|
|
Aaaaaah, okay.
Wenn ich das richtig verstehe dann hast du in einer Variable die Ausgabe von einer anderen Variable, stimmt das?
Wenn ja, dann wirst du es so nicht hinbekommen. Schau dir dazu auch mal das an:
http://www.smarty.net/docs/en/api.register.resource.tpl |
|
Back to top |
|
Lariphos Smarty Rookie
Joined: 10 Jul 2017 Posts: 9
|
Posted: Fri Jul 14, 2017 1:18 pm Post subject: |
|
|
Grizzly wrote: | Aaaaaah, okay.
Wenn ich das richtig verstehe dann hast du in einer Variable die Ausgabe von einer anderen Variable, stimmt das?
Wenn ja, dann wirst du es so nicht hinbekommen. Schau dir dazu auch mal das an:
http://www.smarty.net/docs/en/api.register.resource.tpl |
Korrekt, wenn ich das getrennt machen würde bräuchte ich dafür ja mehrere Teile die einzeln bearbeitet werden müssten, was das ganze viel zu umständlich macht. |
|
Back to top |
|
Grizzly Smarty Pro
Joined: 15 Apr 2011 Posts: 172 Location: Germany
|
Posted: Fri Jul 14, 2017 1:57 pm Post subject: |
|
|
Ja aber wie gesagt. Dazu musst du eine eigene Resource entwickeln. Denn Variablen werden nur im Template ersetzt und nicht in anderen Variablen |
|
Back to top |
|
Lariphos Smarty Rookie
Joined: 10 Jul 2017 Posts: 9
|
Posted: Sat Jul 15, 2017 1:52 pm Post subject: |
|
|
hmm mist, dann werd ich mal versuchen was zu basteln auch wenn ich bezweifle das dafür meine Kenntnisse reichen ^^
Thread kann dann meinetwegen geschlossen werden. |
|
Back to top |
|
Lariphos Smarty Rookie
Joined: 10 Jul 2017 Posts: 9
|
Posted: Sun Jul 16, 2017 8:15 am Post subject: |
|
|
Problem gelöst, nachdem ich mir noch mal ein wenig genauer die Doku durchgelesen habe bin ich auf die bereits eingebaute Funktion eval gestoßen, damit ging das ganze =) |
|
Back to top |
|
|