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 7848931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:22:31+00:00 2026-06-02T18:22:31+00:00

I’m writing my own MVC framework in PHP, just for learning purposes. It wasn’t

  • 0

I’m writing my own MVC framework in PHP, just for learning purposes. It wasn’t really hard to have a router/dispatcher class to call the right controller/action etc.

But now i’m at the part where i’m going to use models. Or actually, the model layer. But there’s something that confuses me.

Alot of other MVC frameworks have a ‘BaseModel’. I’ve read that this is actually bad practise, because the “Model” shouldn’t be seen as another class. But as a real ‘layer’, which can contain things like the ‘mapper’ pattern or ‘repository’ pattern etc.

But to be honest, i don’t see any advantages in that. To me, a ‘BaseModel’ class seems to be the fastest way to go, with the same results.

I can simply do something like:

class User extends BaseModel
{
    // the GetUserBy* could easily be something that's handled by the
    // BaseModel class, like in the Repo pattern.

    public function getUserByName ( $name )
    {
        // no error handling of any kind, just for simplicity
        return $this->db->exec("SELECT * FROM users WHERE name='".$name."'");
    }

    // $data = array
    public function saveUser ( $data )
    {
        // Make sure no extra fields are added to the array
        $user = array ( 'name' => $data['name'],
                        'address' => $data['address']);

        $this->db->autoSave ( $user );
    }
}

But if i’d go for a repository pattern then i have to create the following:
Repositories
Entities
DAO

Entities have Aggregates to other repositories. So basically i’m manually writing out my entire database scheme to objects…

In the end, what’s the difference??? Except that i probably could have saved alot of time by simply using a BaseModel class…

But why is it still considered to be a bad thing then?? It’s not that the repo pattern decouples my application more then i’m doing now. Because to me, those patterns mentioned above seem to be highly overrated. It probably would only work in an application that has a shared state; Save objects locally (in the repository) and commit them later on.

That’s why i think no one can really answer this…

But i’m still hoping to see a decent answer that makes me go: “ahhhh… What was i thinking….”. But if not, then i’m sure about my case that the BaseModel isn’t a bad thing at all and that most bloggers are just a bunch of sheeps 🙂

  • 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-02T18:22:32+00:00Added an answer on June 2, 2026 at 6:22 pm

    It’s not that the repo pattern decouples my application more then i’m
    doing now

    Your application is tightly coupled to SQL database components (which are, in effect, acting as your mapper). However, despite this, your design is much more like a Repository than an Active Record approach (which is likely what most of these bloggers you refer to are griping about).

    Active records encapsulate not only the data, but also the database access:

    $user = new User();
    $user->setUsername('jane');
    $user->setEmail('jane@foo.bar');
    $user->save();
    

    It’s nicer to have the record objects be unaware of the persistence layer (separation of concerns). Your “base” does just that by returning arrays of user data and when those arrays are modified, they must be passed back to the user “base” for saving. You could change your naming to:

    class UserRepo extends BaseRepo
    {
        // user-specific repo code...
    }
    
    $userRepo = $this->getRepo('User');
    $user = $userRepo->getUserByName('jane');
    $user['email'] = 'jane@new.email';
    $userRepo->save($user);
    

    There’s nothing wrong with having a base repo.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.