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

Array aus Datenbank mit Variable

 
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
Lariphos
Smarty Rookie


Joined: 10 Jul 2017
Posts: 9

PostPosted: Mon Jul 10, 2017 4:52 pm    Post subject: Array aus Datenbank mit Variable Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Jul 10, 2017 6:35 pm    Post subject: Re: Array aus Datenbank mit Variable Reply with quote

Lariphos wrote:
"SELECT 'Version'
...
$gameVersion["version"];

I see an apparent issue with your code.
Back to top
View user's profile Send private message
Lariphos
Smarty Rookie


Joined: 10 Jul 2017
Posts: 9

PostPosted: Mon Jul 10, 2017 7:02 pm    Post subject: Reply with quote

when you mean the ' it's just because i write with my mobile phone it doesn't have the normal symbol ^^
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Jul 10, 2017 7:18 pm    Post subject: Reply with quote

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
View user's profile Send private message
Lariphos
Smarty Rookie


Joined: 10 Jul 2017
Posts: 9

PostPosted: Tue Jul 11, 2017 6:48 am    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Jul 11, 2017 6:24 pm    Post subject: Reply with quote

Then check each variable before and after assignment.
Back to top
View user's profile Send private message
Lariphos
Smarty Rookie


Joined: 10 Jul 2017
Posts: 9

PostPosted: Wed Jul 12, 2017 7:35 am    Post subject: Reply with quote

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
View user's profile Send private message
Lariphos
Smarty Rookie


Joined: 10 Jul 2017
Posts: 9

PostPosted: Fri Jul 14, 2017 6:10 am    Post subject: Reply with quote

No idea? Maybe it helps when i upload the script so you can look over it?
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Fri Jul 14, 2017 6:52 am    Post subject: Reply with quote

Kannst du den Template Inhalt schicken, in dem du auch die zwei stellen aufrufst?
Back to top
View user's profile Send private message Visit poster's website
Lariphos
Smarty Rookie


Joined: 10 Jul 2017
Posts: 9

PostPosted: Fri Jul 14, 2017 7:25 am    Post subject: Reply with quote

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:

&copy; 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
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Fri Jul 14, 2017 12:27 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Lariphos
Smarty Rookie


Joined: 10 Jul 2017
Posts: 9

PostPosted: Fri Jul 14, 2017 1:18 pm    Post subject: Reply with quote

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
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Fri Jul 14, 2017 1:57 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Lariphos
Smarty Rookie


Joined: 10 Jul 2017
Posts: 9

PostPosted: Sat Jul 15, 2017 1:52 pm    Post subject: Reply with quote

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
View user's profile Send private message
Lariphos
Smarty Rookie


Joined: 10 Jul 2017
Posts: 9

PostPosted: Sun Jul 16, 2017 8:15 am    Post subject: Reply with quote

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
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