Re: [PHP] Question about template systems
Marcus Gnaß wrote: like with programming questions in general. Should have read my own post before sending! ;) Should be programming languages! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about template systems
Excellent, thanks for your help guys, you've been really helpful :) On 3 Mar 2009, at 10:20, Marcus Gnaß wrote: Matthew Croud wrote: Hello, First post here, I'm in the process of learning PHP , I'm digesting a few books as we speak. I'm working on a content heavy website that provides a lot of information, a template system would be great and so i've been looking at ways to create dynamic data with a static navigation system. So far, using the require_once(); function seems to fit the bill in order to bring in the same header html file on each page. I've also looked at Smartys template system. I wondered how you folk would go about creating a template system ? Smarty is a good choice, although some people might prefer other templating systems. This is kind of a religious question like with programming questions in general. But I guess that most people would advise you to use an existing templating system instead of writing one on your own. My second question might be me jumping the gun here, I haven't come across this part in my book but i'll ask about it anyway. I often see websites that have a dynamic body and static header, and their web addresses end like this: index.php?id=445 where 445 i presume is some file reference. What is this called ? It seems like the system i'm after but it doesn't appear in my book, If anyone could let me know what this page id subject is called i can do some research on the subject. Have a look at the PHP manual and be sure to bookmark it! ;) http://www.php.net/manual/en/ The ID you mentioned is a query. id=445other_id=653 would be a querystring. To retrieve data passed via this querystring you can use $_GET (http://de.php.net/manual/en/reserved.variables.get.php ). Have fun -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about template systems
Hi, First post here, I'm in the process of learning PHP , I'm digesting a few books as we speak. I'm working on a content heavy website that provides a lot of information, a template system would be great and so i've been looking at ways to create dynamic data with a static navigation system. So far, using the require_once(); function seems to fit the bill in order to bring in the same header html file on each page. I've also looked at Smartys template system. If you've looked at require_once() and it fits the bill, then chances are that Smarty might be overkill slightly. I wondered how you folk would go about creating a template system ? I wouldn't (or at least, I wouldn't advise it). Use one that's already out there and save your self some (a lot of) work. My second question might be me jumping the gun here, I haven't come across this part in my book but i'll ask about it anyway. I often see websites that have a dynamic body and static header, and their web addresses end like this: index.php?id=445 where 445 i presume is some file reference. What is this called ? I don't know of the specific name, but the URL is simply passing an identifier (445) to the script (index.php). This ID could be the ID of a record in a database, which is then retrieved and shown to the user. It seems like the system i'm after but it doesn't appear in my book, If anyone could let me know what this page id subject is called i can do some research on the subject. Erm, don't know of the specific name, except that it's a GET parameter (so I guess I do...). Everything following the question mark is collectively known as the query string. You can retrieve these by examining the $_GET variable. You will aalso find some useful things, in $_SERVER. Eg: pre ?php print_r($_GET); print_r($_SERVER); ? -- Richard Heyes HTML5 Canvas graphing for Firefox, Chrome, Opera and Safari: http://www.rgraph.net (Updated February 28th) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about template systems
Matthew Croud wrote: Hello, First post here, I'm in the process of learning PHP , I'm digesting a few books as we speak. I'm working on a content heavy website that provides a lot of information, a template system would be great and so i've been looking at ways to create dynamic data with a static navigation system. So far, using the require_once(); function seems to fit the bill in order to bring in the same header html file on each page. I've also looked at Smartys template system. I wondered how you folk would go about creating a template system ? Smarty is a good choice, although some people might prefer other templating systems. This is kind of a religious question like with programming questions in general. But I guess that most people would advise you to use an existing templating system instead of writing one on your own. My second question might be me jumping the gun here, I haven't come across this part in my book but i'll ask about it anyway. I often see websites that have a dynamic body and static header, and their web addresses end like this: index.php?id=445 where 445 i presume is some file reference. What is this called ? It seems like the system i'm after but it doesn't appear in my book, If anyone could let me know what this page id subject is called i can do some research on the subject. Have a look at the PHP manual and be sure to bookmark it! ;) http://www.php.net/manual/en/ The ID you mentioned is a query. id=445other_id=653 would be a querystring. To retrieve data passed via this querystring you can use $_GET (http://de.php.net/manual/en/reserved.variables.get.php). Have fun -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about template systems
On Tue, Mar 03, 2009 at 09:01:06AM +, Matthew Croud wrote: Hello, First post here, I'm in the process of learning PHP , I'm digesting a few books as we speak. I'm working on a content heavy website that provides a lot of information, a template system would be great and so i've been looking at ways to create dynamic data with a static navigation system. So far, using the require_once(); function seems to fit the bill in order to bring in the same header html file on each page. I've also looked at Smartys template system. I wondered how you folk would go about creating a template system ? Here's a simple way of doing this: Set up a full page of HTML, with the header, footer and all that stuff. But leave the center (content) part of the page blank. You can call what you just built a template. What goes in the center could be called a view. In the center of the page, put a call like this: include($view_page); When you go to display the page, do this: $view_page = 'apples.php'; include('template.php'); When the template page is included, it will, in turn, the view page (apples.php) will get included. This works well if you want the same basic look for all the pages of your site. Just one way to do it. My second question might be me jumping the gun here, I haven't come across this part in my book but i'll ask about it anyway. I often see websites that have a dynamic body and static header, and their web addresses end like this: index.php?id=445 where 445 i presume is some file reference. What is this called ? It seems like the system i'm after but it doesn't appear in my book, If anyone could let me know what this page id subject is called i can do some research on the subject. Most likely, index.php is what is called a front controller (look it up). The id=445 is a GET variable being passed to index.php. The index.php file checks this variable and decides which page to display. It could be a page called anything.php, but index.php knows that when id = 445, it should display this page. An awful lot of websites use a model-view-controller (MVC, look it up) system using a front controller. There are tons of these about. My personal recommendation for about the lightest weight of these is CodeIgniter (codeigniter.com). Being lightweight also allows you to look at its code and easily understand what it's doing and why. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about template systems
2009/3/3 Matthew Croud m...@obviousdigital.com First post here, I'm in the process of learning PHP , I'm digesting a few books as we speak. I'm working on a content heavy website that provides a lot of information, a template system would be great and so i've been looking at ways to create dynamic data with a static navigation system. So far, using the require_once(); function seems to fit the bill in order to bring in the same header html file on each page. I've also looked at Smartys template system. I wondered how you folk would go about creating a template system ? http://stut.net/blog/2008/10/28/snippet-simple-templates-with-php/ My second question might be me jumping the gun here, I haven't come across this part in my book but i'll ask about it anyway. I often see websites that have a dynamic body and static header, and their web addresses end like this: index.php?id=445 where 445 i presume is some file reference. What is this called ? It seems like the system i'm after but it doesn't appear in my book, If anyone could let me know what this page id subject is called i can do some research on the subject. This could be being handled any number of ways. 445 could refer to a row in a database, a file on disk or a number of other things. All you really need to know is that the script will take $_GET['id'], sanitise it (important!) and use it as a resource identifier in a SQL query, filename or something else. That will give the script the content to display. It would likely then include a file containing the common header HTML, output the retrieved content and then include a file containing the common footer HTML. Even at the simplest level you'd probably call this an instance of the front controller pattern (Google it), but they usually go a lot further than this. As far as templating systems go I personally don't think they add anything to the equation unless you're working with designers who are already familiar with something. Separation of logic and content is important, abstraction away from PHP is not (IMHO). -Stuart -- http://stut.net/
Re: [PHP] Question about template systems
On Tue, 3 Mar 2009 20:46:40 +, stuttle wrote: [...] As far as templating systems go I personally don't think they add anything to the equation unless you're working with designers who are already familiar with something. Separation of logic and content is important, abstraction away from PHP is not (IMHO). Yeah, I've been meaning to ask about that myself - what benefit is there in using something like Smarty, which requires learning yet another set of notation, over just having a class/interface for the page and calling methods on that in plain-old PHP from the template? --- the PHP page (e.g. index.php) --- ?php $page = new YourPageClass(); require_once 'include/template.php'; --- template.php --- html head title?php $page-showPageTitle();?/title ... ?php $page-showCustomHeaders();? /head body ... ?php $page-showMenu();? ... ?php $page-showContent();? ... /body /html --- snip For that matter, why go with Smarty over the more widely supported (across multiple languages) XSL? Maybe I'm missing something, but I don't see the point of special templating systems that require you to know yet another notation set, i.e. abstraction away from PHP as Stuart puts it. -- Ross McKay, Toronto NSW Australia Click me, drag me, treat me like an object -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php