Giter VIP home page Giter VIP logo

Comments (8)

lewisgoddard avatar lewisgoddard commented on August 23, 2024
  1. Short php tags are generally discouraged because of things like xml starting with <?xml and ending with ?> as well, however I am not sure how that applies to the short echo tags, but I always do <?php echo $thing; ?> for compatability and so I feel safe. We should probably make a decision on that.
  2. include_once isn't a function, it's a control structure, so it should be formatted include_once 'header.php';
  3. I don't see why we'd want to stop the header being included twice, good code should do that. No need for PHP to keep track of it, that's for function declarations and the like.

from website.

martpie avatar martpie commented on August 23, 2024

I agree on 1. & 2., but not for 3. (or I misuderstood it)

let's imagine something like:

Pages
|- home.php
|- 404.php
|- [...].php

Parts
|- header.php
|- footer.php

In Pages we would have all the content + specific meta of the page (title and description) + 1 include at the top (header) and 1 include at the bottom (footer)

In Parts we would have ... parts !

So:
header.php

<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="author" content="elementary LLC">
        <link rel="shortcut icon" href="favicon.ico">
        <link rel="stylesheet" type="text/css" media="all" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300">
        <link rel="stylesheet" type="text/css" media="all" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">

home.php

        <meta name="description" content="elementary OS, a fast and open replacement for Windows and OS X">
        <title>elementary OS</title>
</head>

<body>
        <div id="content-container">
                blablabla...
        </div>

footer.php

<footer>
            Copyright &copy; 2015 elementary LLC.
            <ul>
                <li><a href="http://blog.elementaryos.org" target="_blank" title="Tumblr"><i class="fa fa-tumblr"></i></a></li>
                <li><a href="https://twitter.com/elementary" target="_blank" title="Twitter"><i class="fa fa-twitter"></i></a></li>
                <li><a href="http://reddit.com/r/elementaryos" target="_blank" title="Reddit"><i class="fa fa-reddit"></i></a></li>
                <li><a href="https://plus.google.com/114635553671833442612" target="_blank" title="Google+"><i class="fa fa-google-plus"></i></a></li>
                <li><a href="https://github.com/elementary/mvp" target="_blank" title="Github"><i class="fa fa-github"></i></a></li>
                <li><a href="https://www.facebook.com/elementaryos" target="_blank" title="Facebook"><i class="fa fa-facebook"></i></a></li>
            </ul>
        </footer>
    </body>
</html>

from website.

cassidyjames avatar cassidyjames commented on August 23, 2024

Yeah, I don't think there's any harm in include_once. :P We definitely wouldn't ever want the header included more than once, so it makes sense.

@KeitIG, I think I prefer keeping the page's HTML to just within the <body> tag. It's a lot easier to make sure all the opening/closing tags line up, and it also keeps the variables up top of each page's file so they can be used in several places within the head.

from website.

cassidyjames avatar cassidyjames commented on August 23, 2024

@lewisgoddard you're right about 1 and 2. Thanks for the heads up (I wrote that code without reference on my break).

from website.

lewisgoddard avatar lewisgoddard commented on August 23, 2024

I don't see how you guys disagree with 3.

I would use include 'part.php'; rather than include_once 'part.php';, that's all. We should never be calling include twice on the header anyway, so PHP shouldn't be using memory keeping track of something that should never happen.

from website.

cassidyjames avatar cassidyjames commented on August 23, 2024

@lewisgoddard that's fair. If there's a performance benefit for using include instead of include_once I have no qualms.

from website.

lewisgoddard avatar lewisgoddard commented on August 23, 2024

There is a minor memory reduction, gut multiplied across thousands of release-day requests, it stacks up. A good general rule of thumb is to use it to stop functions and classes being re-declared (which is a fatal error), rather than template control.

from website.

cassidyjames avatar cassidyjames commented on August 23, 2024

@KeitIG I'm not sure if you've started work on this or not, but for a directory structure, I think this is pretty sensible:

  • index.php
  • 404.php
  • [...any other pages].php
  • images/
    • [image files]
  • styles/
    • [css files]
  • includes/
    • header.php
    • footer.php

Feel free to correct me if I'm wrong. :)

from website.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.