|
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 |
sebpern Smarty n00b
Joined: 20 Nov 2008 Posts: 4
|
Posted: Thu Nov 20, 2008 1:24 pm Post subject: organisation du code |
|
|
Bonjour
Je vous contacte pour un conseil.
Voila ma question : je veux créer un site avec un menu avec des liens.
Voici mon idée : dans ma page index.tpl :
• Faire des liens qui pointent vers la page index.php en passant en paramètre l’action : donc la page que l’on veut afficher
• Un tag : {include file="$file"}
Code: |
{include file="header.tpl"}
<div id="main" style="background-color:#6699cc;">
{include file="$lien"|default:"accueil.tpl"}
</div>
<div>
<a href="index.php?action=ajoutRallye">Ajout Rallye</a>
<a href="index.php?action=voirRallye">Voir rallye</a>
<a href="index.php">accueil</a>
</div>
|
Puis dans ma page index.php :
• Un test sur le $_GET["action"]
• En fonction de ce test je pense inclure la page php correspondante
• Puis assigner à $file le template correspondant
Code: |
<?php
include('rallye.class.php');
require('Include/setup.php');
$smarty = new Smarty_TP_SMARTY();
$texte="smarty ";
$smarty->debugging = true;
$smarty->caching = false ;
if ($_GET["action"]=="ajoutRallye")
{
require('pagePHP/ajoutRallye.php');
}
if ($_GET["action"]=="voirRallye")
{
require('pagePHP/voirRallye.php');
}
$smarty->display('index.tpl');
?>
|
et dc fichier setup
Code: |
<?php
// charge la bibliothèque Smarty
require_once('libs/Smarty.class.php');
// le fichier setup.php est un bon
// endroit pour charger les fichiers
// de librairies de l'application et vous pouvez
// faire celà juste ici. Par exemple :
// require('livredor/livredor.lib.php');
class Smarty_TP_SMARTY extends Smarty {
function Smarty_TP_SMARTY() {
// Constructeur de la classe.
// Appelé automatiquement à l'instanciation de la classe.
$this->Smarty();
$smarty->template_dir = 'templates/';
$smarty->compile_dir = 'templates_c/';
$smarty->config_dir = 'configs/';
$smarty->cache_dir = 'cache/';
//$this->caching = true;
$this->assign('app_name', 'TP SMARTY');
}
}
?>
|
Voila comment je pensais faire, mais ne connaissant pas suffisamment smarty je ne sais pas si une autre solution pourrait être mieux
Merci pour vos idées peut etre en lien avec mon autre pbl [/code] |
|
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
|