Jump to content

How to organize php site?


baris22

Recommended Posts

Hello,

 

I want to organize my php files so i will know where everything is. I want some feedback.

 

This is my root:

 

classes

# class.php

# another_class.php

 

functions

# function.php

# another_function.php

 

config

# config.php

 

files

# footer.php

# header.php

# left.php

# right.php

# top.php

 

images

# logo.gif

# style.css

 

pages

# about.php

# contact.php

# index.php

 

index.php

about.php

contact.php

 

On index.php I have got

<?php
$page_title = "title of site";
$page_keyword = "keywords";

define('_This_IS_not-FOR_YOU', TRUE);

include "config/config.php"; // get config
include "files/header.php"; // get header
include "files/top.php"; // get topmenu
include "pages/index.php"; // get content
include "files/footer.php"; // get footer

?>

 

On pages/index.php I have got

 

<?php defined('_This_IS_not-FOR_YOU') or die('Direct access not allowed.'); ?>
<table width="800" border="1" bgcolor="#FFFF00">
  <tr>
    <td>Index</td>
  </tr>
</table>

 

On files/header.php I have got

 

<?php defined('_This_IS_not-FOR_YOU') or die('Direct access not allowed.'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $page_title; ?></title>
<link type="text/css" rel="stylesheet" href="http://www.namepros.com/images/style.css">
</head>
<body>

Link to comment
Share on other sites

It seems like you've got everything organized in a pretty straightforward manner. I'm not sure about everyone else, but I think as long as you keep things easy to understand and group like files, the file structure isn't as important.

 

If you are worried about future developers having to tinker with the code, a quick readme file including a description of the folders could be handy.

Link to comment
Share on other sites

A class and a function is not the same.

 

could you elaborate on that please...

- classes contain (public, private, etc..) functions to be used later in an object of that class.

- functions are plain functions to be included later in a script.

 

The only way i think of is that you use (classes) if your coding in php5 and (functions) if your coding in php4

using both makes no sense to me :S

Link to comment
Share on other sites

A class and a function is not the same.

 

could you elaborate on that please...

- classes contain (public, private, etc..) functions to be used later in an object of that class.

- functions are plain functions to be included later in a script.

 

The only way i think of is that you use (classes) if your coding in php5 and (functions) if your coding in php4

using both makes no sense to me :S

 

Errrr....  Classes and function are nothing the same.  Classes contain methods, which are basically functions, but functions are all in the global scope, have no sense of a belonging to an object, have no access specifications (private, public...) and other differences.

 

OOP does not simply mean throwing a few Class classname {} lines in a script.

Link to comment
Share on other sites

Really? So when writing object oriented code in PHP5 you never use library functions provided by PHP? That's quite an amazing feat considering the way PHP is designed as a language.

 

Also, OOP is not specifically for PHP5 and procedural for PHP4. You can easily write procedural code in PHP5 as well. If you are aiming for as pure OOP as possible you wouldn't mix these, but it certainly is possible. Because I favor OOP I wouldn't do that, however. Nor would I like to take over such a project.

 

By the way, you don't call the things in objects for functions, but rather methods. Just a minor note on the nomenclature ;)

Link to comment
Share on other sites

Errrr....  Classes and function are nothing the same.  Classes contain methods, which are basically functions, but functions are all in the global scope, have no sense of a belonging to an object, have no access specifications (private, public...) and other differences.

 

OOP does not simply mean throwing a few Class classname {} lines in a script.

 

looks like you misunderstood me i wasn't talking about the actual definition of class x{} and function y{}. i know there is a huge difference...

 

i was saying.. having a class that handles your code for you, doesn't necessarily mean you need hand-made-functions because you could declare these inside the belonging specific class made for this kind of functions.

 

For example: if you made a class that handles Members for your site ... you could declare all the handling member functions in there instead of having to include an external ( member.inc.php ) or w/e.

 

 

Really? So when writing object oriented code in PHP5 you never use library functions provided by PHP? That's quite an amazing feat considering the way PHP is designed as a language.

 

Also, OOP is not specifically for PHP5 and procedural for PHP4. You can easily write procedural code in PHP5 as well. If you are aiming for as pure OOP as possible you wouldn't mix these, but it certainly is possible. Because I favor OOP I wouldn't do that, however. Nor would I like to take over such a project.

 

By the way, you don't call the things in objects for functions, but rather methods. Just a minor note on the nomenclature ;)

 

Another misunderstanding =).. i was talking about hand-made-functions not the actual library functions, ofc you use those inside your class.

 

Which is the reason a function folder doesn't makes sense to me

my point is: If a class folder exist a function folder doesn't need to.. i could be wrong though, i would like to know why =|

Link to comment
Share on other sites

Another misunderstanding =).. i was talking about hand-made-functions not the actual library functions, ofc you use those inside your class.

 

API-wise there is no difference between a function you wrote, PHP's built-in functions, functions provided by PECL extensions, etc. The only difference is how and where they are implemented. When calling a function, PHP doesn't really care where it comes from.

 

i was saying.. having a class that handles your code for you, doesn't necessarily mean you need hand-made-functions because you could declare these inside the belonging specific class made for this kind of functions.

 

For example: if you made a class that handles Members for your site ... you could declare all the handling member functions in there instead of having to include an external ( member.inc.php ) or w/e.

 

That would not be an object oriented approach though. OOP deals with objects, their behavior, state and interaction with each other. It's in no way about grouping similar or related functions together. The latter would still be procedural programming.

Link to comment
Share on other sites

That would not be an object oriented approach though. OOP deals with objects, their behavior, state and interaction with each other. It's in no way about grouping similar or related functions together. The latter would still be procedural programming.

That being an OOP approach or not.. is not the point for now ( it was just an example to show why a function folder is useless ), the point is a function folder doesn't need to exist if a class folder does.

 

>.<

Guys this is turning into kinda angry conversation .. although my goal was purely educational

so I'am signing out.

Link to comment
Share on other sites

No, it takes quite a bit to get me angry.  ">.<" was basically me expressing my feelings in regards to how you responded to Daniel's post.

 

 

Having a functions folder and having a classes folder is entirely justifiable.  Classes and functions are no more related that functions and variables.  Yes functions use variables, but that doens't mean they're equivalent.

 

 

(Ok, in all fairness, function and classes are more closely related than functions and variables, but not by much.)

Link to comment
Share on other sites

If you don't have a reason to place a function in a class, it remains a function instead of a method. You can have class and function folders, they just shouldn't contain similar functions/classes. For example you could create a function that would just include a bunch of config files for you and you could just call that. Putting that into a class might be a bit overkill.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.