How do you organize your PHP scripts and files?

OOP slows down your app

can you show us a benchmark and not just throw words up in the air

<cache>                 [uploaded images, tmp dir, cache folders, etc. Every subfolder has 0777 permissions]
<dev>                   [phpinfo, test scripts, development junk drawer]
<include>               [included files; resources]
   <css>
      style.css         [General styles]
      site.css          [styles that are specific to this site]
      site_cms.css      [styles that are specific to the cms]
      site_front.css    [styles that are specific to the front layout]
   <flash>
   <fonts>
   <images>
      <layout>          [static images used in layout]
      <silk_icons>      [gotta have 'em. http://www.famfamfam.com]
   <js>
      <prototype>
      lib.js            [General JS helper functions]
      site.js           [JS that's specific to this site]
   <php>                [PHP classes and functions]
      <Export>
      <Form>
      <ImageGen>
      <Mail>
      <MySQL>
      <OpenSSL>
      <Page>
      <ShoppingCart>
      <SmartLoader>
      <Thumb>
      <Uploader>
      lib.debug.php     [debug functions]
      lib.functions.php [General PHP helper functions]
      lib.site.php      [PHP functions specific to this site]
   <scripts>            [misc files that are usually fetched with require_once or get_file_contents]
   config.php
   init.php             [auto_prepended in .htaccess]
<pages>                 [contains all of the actual pages in the site. Mod Rewrite is used extensively
   <cms>                [CMS pages]
      index.php
   <front>              [Front pages]
      index.php
.htaccess
robots.txt

I think you might be using classes in the wrong way if you believe this to be true.

Right, which is why classes are better than function libraries.

Does anyone place files in subfolders to further categorize them and prevent clutter, such as:

/library/transferobject/
/library/transferobject/user.php
/library/transferobject/user/detailed.php
/library/transferobject/order.php
/library/transferobject/order/detailed.php
/library/mapper/user.php
/library/mapper/order.php

A large bulk of my scripts are transfer object type classes, but I don’t prefix…

/library/transferobject/user.php

…or suffix them…

/library/user/transferobject.php

into defined directory structures.

This causes a lot of mixing between these classes and classes that actually perform “work”, such as:

/library/user.php
/library/user/mapper.php
/library/order.php
/library/order/mapper.php

How do you deal with this type of clutter and organization when you get deeper into the folder structure?

/
/apps
/apps/w3counter
/apps/w3counter/cache
/apps/w3counter/config
/apps/w3counter/config/app.yml
/apps/w3counter/config/cache.yml
/apps/w3counter/config/config.yml
/apps/w3counter/config/factories.yml
/apps/w3counter/config/filters.yml
/apps/w3counter/config/i18n.yml
/apps/w3counter/config/logging.yml
/apps/w3counter/config/routing.yml
/apps/w3counter/config/security.yml
/apps/w3counter/config/settings.yml
/apps/w3counter/config/view.yml
/apps/w3counter/lib
/apps/w3counter/lib/authnet.class.php
/apps/w3counter/lib/authnetArb.class.php
/apps/w3counter/lib/fusionChart.class.php
/apps/w3counter/lib/googleMap.class.php
/apps/w3counter/lib/searchParse.php
/apps/w3counter/lib/wcPagedDataSet.class.php
/apps/w3counter/lib/wcUser.class.php
/apps/w3counter/lib/utf8ConnectionFilter.class.php
/apps/w3counter/lib/rememberMeFilter.class.php
/apps/w3counter/lib/publicStatsAuthFilter.class.php
/apps/w3counter/lib/helper
/apps/w3counter/lib/helper/StatFormatHelper.php
/apps/w3counter/modules/
/apps/w3counter/modules/live
/apps/w3counter/modules/live/actions
/apps/w3counter/modules/live/actions/actions.class.php
/apps/w3counter/modules/live/actions/components.class.php
/apps/w3counter/modules/live/config
/apps/w3counter/modules/live/config/security.yml
/apps/w3counter/modules/live/config/view.yml
/apps/w3counter/modules/live/templates
/apps/w3counter/modules/live/templates/onlineSuccess.php
/apps/w3counter/modules/live/templates/onlineTable.php
/apps/w3counter/modules/live/templates/referrersSuccess.php
/apps/w3counter/modules/live/templates/referrersTable.php
/apps/w3counter/modules/live/templates/searchesSuccess.php
/apps/w3counter/modules/live/templates/searchesTable.php
/apps/w3counter/modules/admin
...
/apps/w3counter/modules/api
...
/apps/w3counter/modules/auth
...
/apps/w3counter/modules/content
...
/apps/w3counter/modules/navigation
...
/apps/w3counter/modules/rss
...
/apps/w3counter/modules/sources
...
/apps/w3counter/modules/visitors
...
/apps/w3counter/modules/websites
...
/apps/w3counter/templates
/apps/w3counter/templates/ajax_layout.php
/apps/w3counter/templates/account_layout.php
/apps/w3counter/templates/stats_layout.php
/apps/w3counter/templates/_footer.php
/apps/w3counter/templates/_headerbar.php
/apps/w3counter/templates/_navbar.php
/apps/w3counter/templates/_paging.php
/apps/w3counter/templates/_modetabs.php
/apps/w3counter/templates/_site_switcher.php
/cache
...
/config
/config/config.php
/config/databases.yml
/config/propel.ini
/config/properties.ini
/config/schema.yml
/css
/css/main.css
/css/public.css
/data
/data/sql
/data/sql/lib.model.schema.sql
/data/symfony
...
/doc
/images
/images/charts
...
/images/icons
...
/images/counters
...
/js
/js/FusionCharts.js
/js/ClickOverlay.js
/lib
/lib/PeerUtils.class.php
/lib/model
/lib/model/AdminPeer.php
/lib/model/Feed.php
/lib/model/FeedPeer.php
/lib/model/LogEntry.php
/lib/model/LogEntryPeer.php
/lib/model/Style.php
/lib/model/StylePeer.php
/lib/model/Summary.php
/lib/model/SummaryPeer.php
/lib/model/User.php
/lib/model/UserPeer.php
/lib/model/Website.php
/lib/model/WebsitePeer.php
/lib/symfony
...
/log
/log/w3counter_prod.log
/log/w3counter_dev.log
/plugins
/plugins/sfOptimizerPlugin
...
/plugins/sfSslRequirementPlugin
...
/sf
...
/test
/test/bootstrap
...
/test/functional
...
/test/unit
...
/.htaccess
/index.php
/w3counter_dev.php
/symfony.bat
/symfony.php

As long as we’re talking file naming conventions now…

[quote=“mattalexx,post:43,topic:3449”]

I agree that class libraries are better then functions libraries for large projects or for reuse of code.

However, you can reuse code with functions too. Since all classes are, are containers for functions (methods). Classes slow down applications, its a proven fact, so not in all cases are they good for development. Thanks for your insight, but I know how to use classes.

That’s wholely untrue.

This was just generalization. I was not getting into detail about the purposes and usage of classes.

:rolleyes:

This is what I do,

/public_html/ - Php scripts
/public_html/tpl/ - Where I put all my .html template files
/public_html/css/ - CSS files
/public_html/js/ - Javascript files
/public_html/img/ - Images
/lib/ - All library files (Includes php classes to be reused across different sites, when you start a new site, just copy this folder over)
/app/ - PHP classes only to be used on the site.
/conf/ - Configurations for the site

In fact I can:

http://www.webmasterstop.com/56.html

:slight_smile:

This is definitely true. The catch is, the slight decrease in the execution time of a script that uses OOP as opposed to a function library becomes a non issue when you consider the benefits (code reuse, portability, the ability of a programmer to build an object that can be used easily by another programmer that may be less familiar with the app, the list goes on, …).

When I started programming in OOP, I never looked back. The actual size of my scripts is much less and because I was able to use so much of the same code in various applications, my development time literally reduced by 50%. It’s like I built robots to do all the work for me.

Some of this functionality can be applied to function libraries, but why?

Agree, I do the same, but for the beginner that just wants a small app and does not need a goliath web application, then functions will do.

Templates is another thing I don’t get. What is the point in separating the presentation but putting placeholders in, only to drag it all back again and replace the placeholders with the data? Why not just put the data straight in in the first place?

Suppose 10 weeks later you hire a designer to re-skin your site. Say you hire an absolute design genius, but no PHP skills whatsoever.
Would you trust him to go about fiddling with your pages possibly touching the php code and making everything not work?

I don’t mess around with template syntaxes. Instead I just use PHP short tagged variables to represent various page elements or content areas embedded in the HTML code. Besides, for a content-rich site, it’s still necessary to have some loops and conditions.

That’s not a good approach.

  1. Short tags can be disabled, breaking your code. That’s a templating method in itself.
  2. You can still use loops and conditions either via PHP itself as the template lang or via a meta-lang, like for example Smarty uses. The point is keeping business code away from presentation code.

Concentrate on the three-tiers technique and it is just as simple as this

Having used both Smarty and PHP alternate syntax a fair bit over the last six years or so, and now refusing to use Smarty anymore, I’ll chip in with my 2 cents:

Would you trust him to go about fiddling with your pages possibly touching the php code and making everything not work?
Yes, because whether you’re using Smarty or PHP in your “template” files, the perceived danger is the same. Things won’t work in the template. So what? Granted, the gee-wizz designer could do more damage with PHP than with Smarty but that’s probably unlikely. The probable outcome is that the gee-wizz designer will make either basic syntax or logic errors and if that’s the case, the output will be pretty much the same.

I use CodeIgniter framework, base on MVC , it is a good structure and even if you don’t use CI, if you reed the first chapter of the documentation, nice explained, you will see a good example of “order”.