Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

feralam's avatar

OOP-MVC-CRUD-PDO

Hi,

Created an OOP-MVC-PDO-based CRUD operation. It will be appreciated if someone suggest some code improvement or let me know what I have done wrong or which way needs to be done. Thank you

REPO LINK.

https://github.com/ferdausalom/OOP-MVC-PDO-CRUD

0 likes
11 replies
Sinnbeck's avatar

Let me post as I notice things.

First off your controllers folder is lowercase while the namespace is Controllers. Rename the folder to have uppercase C as well if you want to follow psr 4 autoload principles (same goes for other folders)

https://www.php-fig.org/psr/psr-4/

Sinnbeck's avatar

I'm curious as to why the vendor folder has been put on github? Normally the user would just run composer install or composer dump-autoload

And I would personally move index.php into the public directory. I get that it's easier with it in the base folder, but it allows anyone to access any file in all folders

Sinnbeck's avatar

Apart from these things it looks pretty good. I assume it's just something to base a project on and not a framework?

feralam's avatar

@Sinnbeck Done. Thank you for your valuable feedback. It's not for a project or framework. Just trying to learn OOP PHP and MVC patterns.

feralam's avatar

@Sinnbeck if I add the below code in composer then show ERROR, can you pls tell me the problem?

"autoload": {
        "files": [
            "app/helpers.php"
        ],
        "psr-4": {
            "App\": "app/",
            "Database\": "database/"
        }
    }

ERROR: Fatal error: Uncaught Error: Class 'App\Database\Connection' not found

Worked with the below code:

"autoload": {
        "files": [
            "app/helpers.php"
        ],
        "classmap": [
            "./"
        ]
    }
kokoshneta's avatar
Level 27

@feralam That’s because the class App\Database\Connection isn’t located where Composer is expecting it.

Note that in PSR-4, you tell it where to look for classes based on their top-level namespace. When you do "Database\\": "database/", you’re saying that the class Database\Connection should be at /database/Connection.php – but in the actual class itself, you use the namespace App\Database, which falls under App, so Composer expects that class to be located at /app/Database/Connection.php.

If you fix the namespace in the Connection class, it should work.

kokoshneta's avatar

@feralam Yeah, I noticed that after posting; I looked at the source and updated the comment (you have the wrong namespace in your class).

kokoshneta's avatar

@feralam You can use the “Set Best Answer” option on the answer that best answered the question to mark the problem as solved and get it off the unsolved list.

Please or to participate in this conversation.