bilis_money Posted August 27, 2007 Share Posted August 27, 2007 Actually i want my PHP codes to be professionally organize, Yeah, i can understand OOP, but how do you organize them properly? Let say i have a very very BIG project, now what do you do for your first step to organize your php script? then the second step,the third step and so on. How do you also organize the files and folders? I want to hear your experiences. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/66862-how-do-you-organize-your-php-scripts/ Share on other sites More sharing options...
redbullmarky Posted August 27, 2007 Share Posted August 27, 2007 this would depend on how you approach things in generally. i tend to send ALL requests (via a rewrite) through a single file - index.php, rather than having stuff like account.php and login.php, etc. this way, i'll group all my site code into a directory called, for example, app, and the rest in respective places of their own. eg - my root directory might look like this: - app/ - config/ - framework/ - templates/ - uploads/ - css/ - main.css - js/ - scripts.js - mootools.js - img/ - logo.gif index.php favicon.ico whereas only css/js/img directories and index.php and favicon.ico are web accessible. very often i'll move the whole 'app' directory outside the webroot altogether, just for safety. in summary - i find the directory structure the most important for keeping organised, as well as naming conventions of my files. if i have enough files that have much in common, i'll then probably group those into their own directory with a name to suit - eg, classes, models, controllers, funcs, etc Quote Link to comment https://forums.phpfreaks.com/topic/66862-how-do-you-organize-your-php-scripts/#findComment-335174 Share on other sites More sharing options...
bilis_money Posted August 27, 2007 Author Share Posted August 27, 2007 very interesting organization rebull Could you explain this further or show me example of this sentenced that you said below, i tend to send ALL requests (via a rewrite) through a single file - index.php, rather than having stuff like account.php and login.php, etc. thanks in advance again. Quote Link to comment https://forums.phpfreaks.com/topic/66862-how-do-you-organize-your-php-scripts/#findComment-335192 Share on other sites More sharing options...
redbullmarky Posted August 27, 2007 Share Posted August 27, 2007 many people organise files like this: index.php myaccount.php news/index.php news/article.php etc but i tend to prefer things like this through a single index.php file. i might use mod_rewrite to make sure that EVERYTHING after my domain is rewritten, so a request like mydomain.com/news/article/10.htm wont look for page 10.htm inside the articles folder inside the news folder, but will instead rewrite it as: index.php?request=/news/article/10 behind the scenes, and run my application from their by including the necessary classes, etc based on $_GET['request']. there's many reasons i choose to work this way, but the main one is just one point of entry in to my app, and one point of exit. makes things much easier when you want to either make significant changes to the site or you're creating a whole new site from the same codebase. Quote Link to comment https://forums.phpfreaks.com/topic/66862-how-do-you-organize-your-php-scripts/#findComment-335236 Share on other sites More sharing options...
tomfmason Posted August 27, 2007 Share Posted August 27, 2007 index.php?request=/news/article/10 a rewrite for something like that would look like this RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?request=$1 [L] The RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d will not rewrite valid files or directories to index.php. Another alternative to using $_GET would be to do something like Daniel0 describes in his Clean URLs without mod_rewrite tutorial. You would still have to use mod_rewrite to remove the index.php. The same rewrite can be used with the following edit RewriteRule ^(.*)$ /index.php/$1 [L] Also a good general way of doing things is say you have a request like redbulls example /news/articles/10. News would be a controller and articles would be a function within that controller. Whereas 10 is the id of the article. For more on mvc style check out the Wiki article on the Model-view-controller architectural pattern. Quote Link to comment https://forums.phpfreaks.com/topic/66862-how-do-you-organize-your-php-scripts/#findComment-335286 Share on other sites More sharing options...
bilis_money Posted August 27, 2007 Author Share Posted August 27, 2007 wow that's new to me you guys are really advanced on PHP. Pattern cool ... Quote Link to comment https://forums.phpfreaks.com/topic/66862-how-do-you-organize-your-php-scripts/#findComment-335386 Share on other sites More sharing options...
448191 Posted August 28, 2007 Share Posted August 28, 2007 "Pattern cool"... I've got to remember that one, lol... Quote Link to comment https://forums.phpfreaks.com/topic/66862-how-do-you-organize-your-php-scripts/#findComment-336009 Share on other sites More sharing options...
bilis_money Posted August 28, 2007 Author Share Posted August 28, 2007 "Pattern cool"... I've got to remember that one, lol... ha ha ha i know what you are in your mind bro. I know Pattern is the most difficult part of PHP. Lets drink to that.. cheers... I love pattern it will give me 'brain cancer' Quote Link to comment https://forums.phpfreaks.com/topic/66862-how-do-you-organize-your-php-scripts/#findComment-336253 Share on other sites More sharing options...
Liquid Fire Posted August 28, 2007 Share Posted August 28, 2007 index.php?request=/news/article/10 I am not a big fan of this method for getting information from files, never have been. In the places i have seen this used it has been very hard for me to find the file i was am looking for because there is a chain of this file calling this file which calls anopther file which calls another file which calss another file(i think you get the point). Some people like so this is really just a personal standpoint, and has nothing to do with file directory stucture(or should not). i like to follow a common directory style. fro instance my web API i am developing has a directory of this: api(the api root directory which is in the root directory of site) -js --css --images --jquery.js --cluetip.js --etc... -php --classes ---base ----base.class.php ----database.class.php ----etc... ---custom ----site.class.php ----etc.. ---html ----html_element.class.php ----table.class.php ----etc.. --functions ---date_time_functions.php ---etc.. config.php Quote Link to comment https://forums.phpfreaks.com/topic/66862-how-do-you-organize-your-php-scripts/#findComment-336493 Share on other sites More sharing options...
TheFilmGod Posted August 29, 2007 Share Posted August 29, 2007 Well I have a basic structure: Then again I ain't no expert!! root: layout --> All images to make the template of my site element --> Header / Footer / Login - Registrations scripts that I then include () in my pages info --> About Us / contact / terms / sitemap news --> more --> News and more act us extra directores that I use to simply put html in and then their corresponding css. I usually have the script in the needed area. If I need to use a script in more than one directory I move it to element where I then include it. IN the future I might move into other ways. I don't think my is effiecient... lol! Quote Link to comment https://forums.phpfreaks.com/topic/66862-how-do-you-organize-your-php-scripts/#findComment-336949 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.