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

Does every page on a site has to

 
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 -> General
View previous topic :: View next topic  
Author Message
nemesisjack
Smarty n00b


Joined: 13 Dec 2013
Posts: 3

PostPosted: Tue Dec 17, 2013 12:30 am    Post subject: Does every page on a site has to Reply with quote

Hello,

I'm trying to teach myself PHP and Smarty. I'm starting out with something simple: A simple site with just a few pages (home, about, contact, etc.). I have created a template and views for the header and footer and I'm pulling the content dynamically from a MySQL database.

This is a rather simple question but I cannot seem to find an answer:

What is the recommended way to add more pages? Should I have an index.php, then a about.php, a contact.php, etc?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Dec 17, 2013 4:20 pm    Post subject: Reply with quote

make one entry page and use multiple templates. so your URL could look like:

Code:
index.php?page=home
index.php?page=about


or with a little apache rewrite magic:

Code:
/home
/about


Then in the php:

Code:
$page = $_GET['page']; // sanitize me!
$smarty->display("$page.tpl");


You could also go a step further:
Code:
$smarty->assign('page',$page);
$smarty->display('index.tpl');


Then give index.tpl control of what templates are loaded.

index.tpl:
Code:
{include file="header.tpl"}
{include file="$page.tpl"}
{include file="footer.tpl"}


(or use template inheritance, much nicer)
Back to top
View user's profile Send private message Visit poster's website
nemesisjack
Smarty n00b


Joined: 13 Dec 2013
Posts: 3

PostPosted: Tue Dec 17, 2013 7:01 pm    Post subject: Reply with quote

Thank you mohrt.

Your answer really helped me move my search in the right direction.

This is a problem where I feel like I understand the latter stages a lot more than the beginning ones.

So, the user finds this site on google or whatever and goes to mydomain.com, which will display the contents of the index.php/index.php?page=home ?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Dec 17, 2013 7:36 pm    Post subject: Reply with quote

http://www.mydomain.com/

Will pick up index.php if Apache is set to that for the default index page. From there it is up to you. You can setup your default $page to whatever you want, example:

index.php:

Code:
// make $page default to "home" if none is set in the URL
$page = !empty($_GET['page']) ? $_GET['page'] : 'home';
Back to top
View user's profile Send private message Visit poster's website
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 -> General 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