|
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 |
nemesisjack Smarty n00b
Joined: 13 Dec 2013 Posts: 3
|
Posted: Tue Dec 17, 2013 12:30 am Post subject: Does every page on a site has to |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Dec 17, 2013 4:20 pm Post subject: |
|
|
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:
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 |
|
nemesisjack Smarty n00b
Joined: 13 Dec 2013 Posts: 3
|
Posted: Tue Dec 17, 2013 7:01 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Dec 17, 2013 7:36 pm Post subject: |
|
|
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 |
|
|
|
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
|