Jump to content

using smarty in modular web site


mehdi_php

Recommended Posts

hi ,

i previously design and program a web site that have a index page that require various modules as needed via switch statement

assume that this is my index page so we have

 

<?php
require_once('includes/site.config.php');
//in config i have site wide setting , declaring objects , error handling , ....
require_once('includes/header.inc.php');
?>

<!-- content , tables , images , etc ... goes here -->

in main content center table i have this switch

switch($_GET["section"]){
case 'register':
require_once('modules/register.php');
break;
case 'about':
require_once('about.php');
break;
case 'users_list':
require_once('users_list.php');
break;
case 'news' :
require_once('modules/news.php');
break;
case 'site_policy':
require_once('site_policy.php');
break;
case 'contact':
require_once('modules/contact.php');
break;
default:
break;
}
<!-- after htmls include footer file -->
<?php include('includes/footer.inc.php');?>

 

now i learn smarty and i like to this web site have a template engine , the problem is i don't know how to assign this functionality to a tpl file plus in many place in the index page

i have to add another section and it's just possible with switch

for example : i have to require profile module and if this module called by user other modules like news , login, etc .. will be removed . so i use the following line of code :

 

if($_GET['section'] == 'profile'){

//do this and require news or login .etc .

}else{

require('path/to/profile.php');

}

an screen shot of site structure here :http://i34.tinypic.com/2mxgxz4.jpg

i think this task could be done like this

$smarty ->assign("section" , $_GET['section'] ) ;
//because the $_get super global return array
$smarty ->display("index.tpl");

then use {foreach } , {if} and {ifelse} statement to determaind switch

but i go thought many search but i can't find any professional programmer do such thing . so please let me know if there is a better solution to still writing entire web application

in one file and use smarty with it , without using switch to determine section to require modules .

 

Regards .

Mehdi .

 

Link to comment
https://forums.phpfreaks.com/topic/124495-using-smarty-in-modular-web-site/
Share on other sites

may be i describe my issue in hard way , the main question is how to use php and smarty in modular web site ?

dose anyone know any tutorial about this subject ?

 

i use switch statement to read url and provide user module as needed .

and i have 1 page (index.php) this page require other modules via switch statement . like this >>

switch($_GET['section']){
case contact : 
require_once('modules/contact.php');
break ;
}

 

the i must assign this work to tpl file . but i don't know how .

 

i hope you understand now .

May be you could use

 

$section = $_GET['section'];
switch($section){
case contact : 
require_once('modules/contact.php');
$smarty ->assign("section" , $section ) ;
break ;
}
$smarty ->display("index.tpl");

 

You could include a file with the name "section" in index.tpl file.

In this case it will be contact.tpl

ok . tanks .

 

but what if i want use something like this in my index.php file

 

if($_GET['section'] == 'profile') {
//do something 
}

 

how i can perform this one via smarty . and is it a common way in using smarty in modular web site may be there is an efficent way to do this i want to find that way .

 

for example define an array and put all of the assigns to it then use this

 

$smarty-> assign('parts' , $P[]) ;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.