SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why use include and stf files.

    Hey,

    I have a general question about developing PHP websites. I have currently been updating a website which i did not create. It was part of my job to alter slight areas etc..

    I realised that the website did not have pages with full HTML and PHP, it had "MANY" include files. For example I will show you one of the pages below:-

    PHP Code:
    <?
      
    require "Site.class.php";
      
    $site = new Site();
      
      
    $site->setDesc("The online social networking site for the fashion and apparel industry across the UK, join us at one of our monthly business networking evenings, parties, press evenings and master classes. Subscribe now as a full member to make the most out of your profile");
      
    $site->setKeywords("Fashion Network, The Fashion Network, Manchester Fashion, London Fashion, Fashion London, Fashion in Manchester, Fashion in London, England, Manchester, London, Fashion, Fashion Events, Retail Recruitment, Fashion Recruitment, Shopping Guide, Fashion Directory, Galleries, Model Agencies, Model Directory, Fashion Photography, Photography Directory, Fashion Blogs, Fashion Podcasts, Fashion Seminars, Retail Seminars, Trend Master Classes, Trends Forecasting, Fashion PR, Fashion Events, Networking, Business Networking");
      
    $site->getHeader('home'$site->sitename);
      
      
    /* include city specific homepage */  
      
    include "index-".$site->location.".stf";
      
        
    $site->getFooter();
    ?>
    Why is it necessary to have $site->getFooter(); and include "index-".$site->location.".stf"; when you can simply have all the code on one page?

    Can some one give a detailed answer please because i have been advised that i need to start developing my websites the same way.. I dont even know what the $site-> stands for, can somebody please help..?

    Regards

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $site is an instance of the class Site().

    The reason you split things up is because it is way easier to edit single files and have it change everything that includes that certain file.

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    A good place to start would be to look closely at Site.class.php

    It seems to feature public properties like $site->location, which suggests it is either written in PHP4 or is not using best practices if it is written in PHP5.

    It should ideally be using accessors like $site->getLocation().

    Either way it may not be the best class to learn from

    Good place:

    http://www.php.net/manual/en/language.oop5.php

  4. #4
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Thanks guys. Well i have been writing PHP and have never split files up..

    How do i know if i am writing in PHP4 or 5? I use MS Expression Web as i have been taught that when studying, dont really like Dreamweaver..

    Regards

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,607
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Unlike the client side layers where each layer uses a different language

    HTML - content layer
    CSS - appearance layer
    JavaScript - behaviour layer

    several of the server side layers share the same language (and so some people jumble them into one rather than making them separate layers so as to make it easier to maintain.

    PHP - page template layer
    PHP - business rules layer
    PHP and mySQL - data layer

    Depending on the complexity of the site you can end up with five or six layers on the server side of things but for most sites those three should be sufficient.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You need to do
    PHP Code:
    <?php
    phpinfo
    () ;
    ?>
    to see what version you are running.

    PHP4 code is largely compatable with PHP5, but OOP code, such as you are talking about in your original post had many changes between 4 and 5.

    I gave you a link for PHP5 OOP there is also a PHP4 OOP page if you really want to grok the diffs.

    The 2 biggest ways to tell if your old class you have there is written for PHP5 is if it contains a method (function) named __construct() , or if you see the some property declarations starting with the words public, protected or private.

    Those are good indicators its written in PHP5.

    If you see a method called the same name as the class, and you see the word "var" before property declarations you are probably safe to say it was written in/for PHP4.

    BUT both style will continue to work in PHP5.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •