Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7798509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:01:53+00:00 2026-06-02T00:01:53+00:00

I have some trouble getting a good folder structure in my project and i

  • 0

I have some trouble getting a good folder structure in my project and i would like to know what other ways i could use to structure my files.

I’m currently working in an MVC sturctured folder.

www/
  Controllers/
  Models/
  Views/

Nothing special so far. But i’m also using an ORM system. With it i can easily get an ‘object’ from my database like:

ORM::load('table');

Now this sort of code should reside in a Model right? So i’d get something like this:

<?php
class userModel
{
    public function getAllUsers ( )
    {
        return ORM::load('table');
    }

    public function getUserById ( $id )
    {
        return ORM::load('table', 'userid=?', array($id));
    }
}
?>

Looks good so far in my opinion… But there’s one more thing. I can also specify a ‘model’ when using the ORM system. With this model i can basically set up validation rules. Like so:

ORM::withModel('authModel');

This lets the ORM know that before it adds a new row (or updates an existing one) to the DB, that it should check the following model first for validation rules.

<?php
class authModel //Or maybe authValidation??
{
    // Method gets automatically triggered when an update is done with the ORM
    public function onUpdate ( $obj )
    {
        if ( $obj->username == '' )
            throw new \Exception('No username');
    }

    public function onInsert ( $obj )
    {
        // Validations here too.
    }
}
?>

Now the problem is, is that i have 2 sorts of models. One where i basically use getters/setters to get and store data to the database (from my controller to my model).

And i have another model in which validation rules are set… I don’t want to mix both in the same folder. So i must come up with another structure for this. Something like:

www/
  Controllers/
  Models/
    Repositories/
    Entities/
  Views/

It’s just that my model isn’t a real ‘repository’, since it doesn’t store any objects in the repo class and doesn’t have a commit() method or anything like that.

I also can’t store the 2nd model (for validations) in the Entities folder, because they’re not Entities at all…

Any idea how i should structure this..??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:01:55+00:00Added an answer on June 2, 2026 at 12:01 am

    The first thing you should understand is that the Model in MVC is not a class/object. It is a layer, made from a multitude of objects. I’m too lazy to do the same song’n’dance again , so just read this comment (skip to the “side notes” section).

    The root of your confusion lies in the fact that you recognize two different responsibilities in the group of classes you call “models”. You are actually having class instances responsible for business logic ( like your UserModel class ), and a separate thing called “ORM”, which loads and stores content. And you have authentication, which does not fit in either of the groups.

    I would go with a structure like this:

    /application
        /modules
            /public
                /controllers
                /templates
             /admin
                /controllers
                /templates
             ....
        /views
        /model
            /logic
            /persistence
            /services
    /framework
    

    You might notice that there is a separate /views folder in /application and also each module has a separate /templates. That is because, in proper MVC the Views are instances of classes, responsible for presentation logic and usually juggle multiple templates. If well written, they too are a reusable structure.

    And the final note: Do not try to use ORMs. Make a datamapper for each domain object which requires it. Some people consider ORMs to be antipatterns. Also, avoid static calls .. thats not OO code. You could benefit a lot from learning about dependency injection

    .. my 2 cents

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

iI have some trouble getting sth like this to work in java: public class
Im having some trouble getting on with my first codeigniter project, and i have
Im having some trouble getting the syntax right. I have a movie clip that
Good Morning, i have some Trouble with the Zend Framework and Zend_DB_Select, i want
I have some trouble in getting Java to read the first character in a
I am have some trouble getting Entity Framework to handle a many to many
I'm having some trouble getting the hang of HQL. I have an application where
I'm pretty new to rails, and I have some trouble getting the philosophy and
I have been having some trouble getting the following to work: <IfModule mod_rewrite.c> DirectoryIndex
I have some trouble getting this particular kernel patch to compile correctly with my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.