|
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 |
oskarr Smarty n00b
Joined: 25 Oct 2004 Posts: 3
|
Posted: Mon Oct 25, 2004 2:10 pm Post subject: Überprüft bitte meinen Code. |
|
|
[php:1:fccba57f4b]
<?php
//Classen includieren//
require_once './classes/Smarty.class.php';
//Neues Smarty starten =)//
$smarty = new Smarty;
//Smartysetup//
$smarty->compile_check = false;
$smarty->debugging = false;
//Inhalt zu Smarty zuweisen//
include_once('./configs/bereichconfig.php');
if(isset($_GET['section']) AND isset($dateien[$_GET['section']]))
{
//Ist eine $_GET Variable vorhanden wird PHP angewiesen
//zu prüfen ob die Datei existiert und diese dann zu laden
if(!file_exists($dateien[$_GET['section']]));
$datei=require $dateien[$_GET['section']];
$smarty->assign("mainbody","$datei");
}
else {
$home=require ('home.php');
$smarty->assign("mainbody","$home");
}
//Titel//
$smarty->assign("TITLE","index.php von localhost");
//Ausgabe im Template//
$smarty->display('index.tpl');
?>[/php:1:fccba57f4b]
Wenn man später, die Abfrage stattfindet, was denn für eine Getvariable übermittelt wurde, wird dann in meinem Template als Mainbody ein File includiert. Das funktioniert so an sich gut, aber, wenn man sich dann die Seite ansieht, taucht auf einmal in dem nach dem Satz aus dem Includefile eine 1 auf, woran kann es liegen? |
|
Back to top |
|
b166-er Smarty Rookie
Joined: 22 Oct 2004 Posts: 29 Location: Germany, Wiesbaden
|
Posted: Mon Oct 25, 2004 2:25 pm Post subject: |
|
|
ganz einfach, weil man den output von require()-funktion nicht in eine variable speichern kann. deshalb gibt es nur eine 1 zurueck, also ein TRUE, das dein require befehl, die datei includen konnte.
wenn du in smarty dateien includen moechtest, dann nimm smarty funktion:
{include ...} siehe manual
und noch ne anmerkung zum code:
falsch/schlecht: [php]<?php $smarty->assign("mainbody","$home"); ?>[/php]
gut: [php]<?php $smarty->assign('mainbody',$home); ?>[/php]
hier die erklaerung dazu: http://www.php-faq.de/q/q-fehler-konstante.html
viel glueck
________
Twin cities assembly plant
Last edited by b166-er on Sun Feb 13, 2011 6:18 pm; edited 1 time in total |
|
Back to top |
|
oskarr Smarty n00b
Joined: 25 Oct 2004 Posts: 3
|
Posted: Mon Oct 25, 2004 2:33 pm Post subject: |
|
|
Danke sehr, und wie kann ich das ganze anders umschreiben, damit die 1 nicht mehr auftaucht? Ich habe die Variablen weggemacht, aber die 1 taucht trotzdem auf. =)[php:1:d9ac816842]
<?php
//Classen includieren//
require_once './classes/Template.class.php';
//Neues Smarty starten =)//
$smarty = new Smarty;
//Smartysetup//
$smarty->compile_check = false;
$smarty->debugging = false;
//Inhalt zu Smarty zuweisen//
include_once('./configs/bereichconfig.php');
if(isset($_GET['section']) AND isset($dateien[$_GET['section']]))
{
//Ist eine $_GET Variable vorhanden wird PHP angewiesen
//zu prüfen ob die Datei existiert und diese dann zu laden
if(!file_exists($dateien[$_GET['section']]));
$smarty->assign("mainbody",include $dateien[$_GET['section']]);
}
else {
$smarty->assign("mainbody",include ('home.php'));
}
//LOL//
$smarty->assign("TITLE","index.php von localhost");
//Ausgabe im Template//
$smarty->display('index.tpl');
?>[/php:1:d9ac816842] |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Mon Oct 25, 2004 2:40 pm Post subject: |
|
|
Wie wärs damit?
[php:1:17155e934f]
<?php
//Classen includieren//
require_once './classes/Template.class.php';
//Neues Smarty starten =)//
$smarty = new Smarty;
//Smartysetup//
$smarty->compile_check = false;
$smarty->debugging = false;
//Inhalt zu Smarty zuweisen//
include_once('./configs/bereichconfig.php');
if(isset($_GET['section']) AND isset($dateien[$_GET['section']]))
{
//Ist eine $_GET Variable vorhanden wird PHP angewiesen
//zu prüfen ob die Datei existiert und diese dann zu laden
$maintpl = 'home.php';
if( file_exists($dateien[$_GET['section']]));
$maintpl = $dateien[$_GET['section']];
}
$smarty->assign("maintpl", $maintpl);
//LOL//
$smarty->assign("TITLE","index.php von localhost");
//Ausgabe im Template//
$smarty->display('index.tpl');
?>
[/php:1:17155e934f]
und im template dann
Code: |
{ include_php file=$maintpl }
|
|
|
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
|