views:

48

answers:

2

ive created an mvc which has this level of organization as far as the folders and settings files go.

+[admin]
-[js]
-[css]
-[images]
-[classes]
--list of php classes
-[includes]
--config.php (includes db connection str
--functions.php (php functions)



--root---

[js]
[css]
[images]
[classes]
--list of php classes
-[includes]
--config.php (includes db connection str
--functions.php (php functions)


the problem i have with this structure is as you can see the administration section has its own folders of classes,functions, and a db configuration file.

then the root for other pages has its own set of pages for classes,functions, and db connection(which is the same as admin)

ive tried having only one folder for classes and another for includes and so on that the admin section and the root pages all share but the outcome of it becomes a mess of includes such as a spider web.

the method of including ive tried is

include_once(dirname(FILE)./directory/...) and what this does is if im inside of a folder and im trying to include a file that is one level up into the current page it wont work. and instead of it using the main root directory it includes the folder im inside as well. so that doesnt come to any good use.

so if this was my root: d:/wamp/www/website/ and i was including something from the main root into a file inside of a directory named functions the dirname(FILE) would actually have a value of d:\wamp\www\website\functions\

whats a good method of including files witout getting into a mess of errors trying to figure out whats going on.

thanks

+1  A: 

Try something like this, and define it in a central config file.

This will give one one single constant for all your paths, then define a few other constants, probably one for each folder as ROOT_CLASSES and ADMIN_CLASSES, with the appropriate file paths attached. Then it is really simply to include stuff. Just describe it with the constant and add the file name.


define("ABS_PATH", "/path/to/upper/most/directory"); // Manual

// define other paths...
define("ADMIN_CLASSES", ABS_PATH . "/admin/classes/");
define("ROOT_CLASSES", ABS_PATH . "/root/classes/");

include(ROOT_CLASSES."/myclass.php");

If this is in the config file, along with other declarations, you won't need to worry about defining them later.

Chacha102
i was thinking of defining these variables within php.ini how would i do that?
You aren't able to do that. php.ini defines how PHP runs, not the constants it has.
Chacha102
A: 

This is how I layout pretty much all my custom websites.

  • [site] this directory only has one file index.php and is the domain root
    • [js]
    • [css]
    • [images]
  • [model]
  • [view]
  • [controller]
  • [lib] - 3rd party code, PHPMailer and such
  • [config]
  • [admin]
    • [js]
    • [css]
    • [images]
    • [model]
    • [view]
    • [controller]

I use __autoload for including files. There are a number of ways to optimize its performance and you don't have to worry about includes.

I only put admin specific code under admin so things like jQuery which gets used by both public access and admin access goes in site/js.

gradbot
what type of stuff go inside model, view, and controller?
Model, View and Controller classes I should imagine :)
Peter Spain