SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Location
    Hong Kong
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Directory structure for MVC or DAO

    Thanks all the experts here provided many valuable threads for MVC and DAO design patterns. I've got many ideas and knowledge.

    I would like to ask that how do you structure your directory? There are many classes (DAO, DO, model, view, controller, supporting classes, etc.) and other files (html, js, css, xml, etc.) in one web application.

    /
    conf
    images
    languages
    libraries
    css
    js
    php
    Any comment?

    Thanks.

  2. #2
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a folder named 'media', and under this folder I have one folder each for images, css, js and flash if required

    Core library functionality appears under a 'packages' folder, ie login and authentication for example are under 'packages/common/'.

  3. #3
    SitePoint Guru
    Join Date
    Dec 2003
    Location
    oz
    Posts
    819
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeh, I've been meaning to start a thread on this.

    I'm less concerned about config files, or libraries, but now that there are so many objects associated with each domain object (the object, objMapper, objFinder, etc ...), does everyone lump all Domain Object related objects into one folder ?

    At the moment, I have a BusinessObejcts folder and a BusinessObjectMappers folder and thats fine. But when I create objects that arent mappers or objects - such as OrderFiller - I don't wanna make a folder for each group of objects.

    Abstract classes, I of course put in the folder that I have all those classes. So abstract Mapper goes in the same folder as all the mapers, etc..

    Just windering how everyone else does it.

    Oh .. and of course, it goes without saying that all your files that arent displayed (templates, classes, etc...) aren't in a publicly accessible folder.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Location
    Hong Kong
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.

    If the abstract classes are placed in different folder from original classes, then the path of import should be hardcode?

    Oh yes, one more question, how about the conf about the application? All of you will include these conf in the object? Or in a conf file and then import inside the class?

  5. #5
    SitePoint Zealot David C's Avatar
    Join Date
    Nov 2003
    Location
    New York!
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The best advice I can give is to look at your code use and reuse (if you reuse certain files together, keep them together -- e.g., a file might hold all your DB classes). Don't separate for the sake of separation; there's no point in having as many folders as you do files.

    Also, you might want to consider keeping everything for one module/controlle in the same folder rather than having folders for controllers, models, and views.

  6. #6
    SitePoint Guru
    Join Date
    Dec 2003
    Location
    oz
    Posts
    819
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, you might want to consider keeping everything for one module/controlle in the same folder rather than having folders for controllers, models, and views
    But of course, if you have 40 or 50 objects (which is common for med-sized apps), then you have 40-50 folders - which is alot when they all have an object, it's mapper and its finder in each one, and not much else

  7. #7
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh yes, one more question, how about the conf about the application? All of you will include these conf in the object? Or in a conf file and then import inside the class?
    What I do now is to parse the configuration once, and store it as an array to a SESSION variable

    Most configuration files are not all that big anyways, so this seams a safe approach to take.

    SweatJe stores errors as a stack to the SESSION as well, and I'm planning to look at this as well but I don't know if it's (for me) going to be worth it, as I want all errors to be FATAL, regardless in any applications etc.

  8. #8
    SitePoint Guru
    Join Date
    Dec 2003
    Location
    oz
    Posts
    819
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Widow Maker
    What I do now is to parse the configuration once, and store it as an array to a SESSION variable
    That's a great idea. Essentially making it a global across multiple pages of a user. Never thought of that.

    I guess storing the errors in a session means that you can have more information available on the error page when you redirect there.

  9. #9
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yer, though still to put some more thought into it myself

    Now I'm actually thinking that I should redirect on all errors, regardless. Then if an error is fatal, only then email is then sent.

    All others are just logged to XML, database, whatever. Will let you know how I get on

    Here is a piece of what I have just now,

    PHP Code:
    # index.php
    ...
    session_start();
        
    error_reportingE_ALL E_STRICT );
        
        @require_once( 
    'packages/common/utilities.class.php' ); /* E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE */
        
        
    if( !isset( $_SESSION['enabled'] ) || empty( $_SESSION['cfg'] ) ) {
            try {
                
    $config = new configuration'config/configuration.ini' );
                
                
    $_SESSION['enabled'] = true;
                
    $_SESSION['cfg'] = $config -> fetch();
            } catch ( 
    Exception $e ) {
                
    // redirect on FATAL errors
                
    $log = new logger'logs/error.log' );
                
    $log -> append$e );
            }
        }
    ... 
    --EDIT--

    Might be advisable also to encrypt your configuration data when I remember to mention it

    Just as a precaution if for example, your shared hosting ?
    Last edited by Widow Maker; Sep 3, 2004 at 12:39. Reason: bleehhh!!

  10. #10
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Location
    Hong Kong
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Although it's already out of this subject, it's still valuable to discuss ~

    Put the configuration in the $_SESSION is really a good idea. However, if there are hundreds of visitors at the same time and all of them have to create the session with the configuration info, will it be a problem of the memory usage and/or CPU usage and/or harddrive space?

    My idea is use the Front Controller object to handle the configuration array, and then pass by reference to other objects which need the configuration array. This still keeps that all the object can access this configuration array.

  11. #11
    SitePoint Zealot prefab's Avatar
    Join Date
    Jan 2003
    Location
    Belgium
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I currently use the singleton/registry pattern to store configuration settings at runtime. Using this registry you have much of the advantages of the dreaded global variables, while avoiding scoping issues and such. It means that any component of an app can access it if needed. Off coarse, one should make sure it isn't misused.

  12. #12
    SitePoint Guru
    Join Date
    Dec 2003
    Location
    oz
    Posts
    819
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's a good idea also. I was thinking that a global would be a good idea also.

    The diference being that session data persists across multiple pages, but takes up persistent space. Where as the singleton doesn't.

    Any comments on the actual thread title by the way?

  13. #13
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    Montreal
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use the following simple directory structure :
    root
    |
    | <library, DAO, configuration and language>
    |
    +-- model
    +-- view
    | |
    | + template engine
    |
    +-- controller

  14. #14
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Location
    Hong Kong
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by louism
    I use the following simple directory structure :
    root
    |
    | <library, DAO, configuration and language>
    |
    +-- model
    +-- view
    | |
    | + template engine
    |
    +-- controller
    Wow, really simple.

    I would like to ask that if you have a dozen for each of DAO classes, library, language files, then the root directory will contain more than 50 files. Will this make you confusion?

  15. #15
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    Montreal
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I only use one data access layer, DB.php, and one library wich includes all required files. The language files & conf files could eventually be moved to a configuration directory, but I currently only have one conf and one lang file

    -Louis

  16. #16
    SitePoint Guru
    Join Date
    Dec 2003
    Location
    oz
    Posts
    819
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeh thats fine if you use active record where everything to do with a class is on one class, but what do you do when you have User, UserMapper, UserFinder, UserIterator, etc... for each of 50+ domain object?

  17. #17
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    New Jersey
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by waimichael
    Wow, really simple.

    I would like to ask that if you have a dozen for each of DAO classes, library, language files, then the root directory will contain more than 50 files. Will this make you confusion?
    I don't think its that simple if thats all he needs for his script. Not everyone makes massive scripts, and I feel that the layout of the directory is often project specific, while some layout standards should be upheld from project to project, core things that are a must.

  18. #18
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Location
    Hong Kong
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by evolve
    I don't think its that simple if thats all he needs for his script. Not everyone makes massive scripts, and I feel that the layout of the directory is often project specific, while some layout standards should be upheld from project to project, core things that are a must.
    Yes, absolutely agree. So here I just want to know how the people structure their project directory and get some ideas or standard.

    The other point is that "Not everyone makes massive scripts". Similar as me, I always seperate a large file into several class files. That's one of the reason why I would like to know about the directory structure.

  19. #19
    Non-Member Big Fat Bob's Avatar
    Join Date
    Sep 2004
    Location
    United Kingdom (Come)
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.imperva.com/application_d...nter/tools.asp

    Came across this website today, and if you scroll down towards the bottom of the page, there is a tool for mapping a sites directory structure.

    Thought it might be of use to some one reading this thread


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •