baris22 Posted August 21, 2009 Share Posted August 21, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/171264-how-to-organize-php-site/ Share on other sites More sharing options...
xangelo Posted August 23, 2009 Share Posted August 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/171264-how-to-organize-php-site/#findComment-904558 Share on other sites More sharing options...
Daniel0 Posted August 23, 2009 Share Posted August 23, 2009 Seems okay, except you should just place the files you don't want people to access outside of the document root. Quote Link to comment https://forums.phpfreaks.com/topic/171264-how-to-organize-php-site/#findComment-904578 Share on other sites More sharing options...
zVirx Posted August 23, 2009 Share Posted August 23, 2009 Just wondering why you have (classes) and (functions) folders they are both the same thing, unless you mean classes in none OOP manner ! Quote Link to comment https://forums.phpfreaks.com/topic/171264-how-to-organize-php-site/#findComment-904605 Share on other sites More sharing options...
Daniel0 Posted August 23, 2009 Share Posted August 23, 2009 A class and a function is not the same. Quote Link to comment https://forums.phpfreaks.com/topic/171264-how-to-organize-php-site/#findComment-904606 Share on other sites More sharing options...
zVirx Posted August 23, 2009 Share Posted August 23, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/171264-how-to-organize-php-site/#findComment-904662 Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/171264-how-to-organize-php-site/#findComment-904666 Share on other sites More sharing options...
Daniel0 Posted August 23, 2009 Share Posted August 23, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/171264-how-to-organize-php-site/#findComment-904668 Share on other sites More sharing options...
zVirx Posted August 23, 2009 Share Posted August 23, 2009 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 =| Quote Link to comment https://forums.phpfreaks.com/topic/171264-how-to-organize-php-site/#findComment-904678 Share on other sites More sharing options...
Daniel0 Posted August 23, 2009 Share Posted August 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/171264-how-to-organize-php-site/#findComment-904680 Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 >.< Quote Link to comment https://forums.phpfreaks.com/topic/171264-how-to-organize-php-site/#findComment-904683 Share on other sites More sharing options...
zVirx Posted August 23, 2009 Share Posted August 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/171264-how-to-organize-php-site/#findComment-904693 Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 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.) Quote Link to comment https://forums.phpfreaks.com/topic/171264-how-to-organize-php-site/#findComment-904704 Share on other sites More sharing options...
xangelo Posted August 24, 2009 Share Posted August 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/171264-how-to-organize-php-site/#findComment-904805 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.