{"id":23537720,"url":"https://github.com/prod3v3loper/php-mvc-professional","last_synced_at":"2025-10-12T17:24:33.539Z","repository":{"id":159024010,"uuid":"380864062","full_name":"prod3v3loper/php-mvc-professional","owner":"prod3v3loper","description":"🏗  A PHP Model View Controller something more professional","archived":false,"fork":false,"pushed_at":"2024-05-13T20:46:23.000Z","size":1132,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-26T03:18:58.566Z","etag":null,"topics":["framework","model-view-controller","mvc","php","scaffold-template","template","template-project"],"latest_commit_sha":null,"homepage":"https://prod3v3loper.github.io/php-mvc-professional/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prod3v3loper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-28T00:23:22.000Z","updated_at":"2024-05-13T20:46:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"fe37a0ae-8fc5-4eda-ad3f-f94d860bb79f","html_url":"https://github.com/prod3v3loper/php-mvc-professional","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prod3v3loper%2Fphp-mvc-professional","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prod3v3loper%2Fphp-mvc-professional/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prod3v3loper%2Fphp-mvc-professional/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prod3v3loper%2Fphp-mvc-professional/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prod3v3loper","download_url":"https://codeload.github.com/prod3v3loper/php-mvc-professional/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239250719,"owners_count":19607516,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["framework","model-view-controller","mvc","php","scaffold-template","template","template-project"],"created_at":"2024-12-26T03:19:02.798Z","updated_at":"2025-09-19T07:16:28.615Z","avatar_url":"https://github.com/prod3v3loper.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🏗 PHP MVC Professional\n\n\u003e Model View Controller\n\n# IDEA\n\nMVC has a clear and understandable structure. A basic framework for smaller or larger projects.\nWorking with it should be easy and understandable, which is why most of the names are named accordingly.\n\nAt the moment there is (further information will follow):\n\n- The Model View and Controller folders are named in the same way.\n- Everything that is still needed is in core folder e.g. templates, less, javascript etc.\n- The Autoloader runs independently equal to - https://github.com/prod3v3loper/php-auto-autoloader\n- The Style CSS repo coming soon used in this template.\n- The Database connection is available PDO\n\n# DOCUMENTATION\n\nRoute all acces to site to the index.php with a `.htaccess` file otherwise routing will not work.\n\n```php\n\u003cIfModule mod_rewrite.c\u003e\n    RewriteEngine on\n    RewriteCond %{REQUEST_FILENAME} !-f\n    RewriteRule ^(.*)$ index.php [L]\n\u003c/IfModule\u003e\n```\n\n# CONTROLLER\n\nThe controller handle the routing of the sites.\n\n\u003e The front controller is the router and directs all inquiries that come from the index.php to the respective controller and action (class method).\n\n`URL/controller/action/`\n\nIf we enter the following in the url:\n`URL/index/about/`\nthe IndexController class and the aboutAction method are called\n\nWith our index controller, however, we do not need the index in the URL but can call it up:\n`URL/about/`\n\n```php\nclass IndexController extends AbstractController\n {\n    public function aboutAction(array $params = [])\n    {\n        V::addContext('data', array());\n        V::display();\n    }\n\n    public function contactAction(array $params = [])\n    {\n        V::addContext('data', array());\n        V::display();\n    }\n }\n```\n\n**EXAMPLE**\n\n`URL/contact/`\n\nThis does not apply to all other controllers only to the IndexController.\n\n```php\nclass UserController extends AbstractController\n{\n    public function loginAction(array $params = [])\n    {\n        V::addContext('data', array());\n        V::display();\n    }\n\n    public function registerAction(array $params = [])\n    {\n        V::addContext('data', array());\n        V::display();\n    }\n}\n```\n\n**EXAMPLE**\n\n`URL/user/register/`\n\n`URL/user/login/`\n\n# MODEL\n\nThe modals handle the database processing. Query, insert, update, delete and validation.\n\n\u003e The database should not be accessed anywhere else, but always via the modals. If a new one is required, it must be created.\n\n## GETTER \u0026 SETTER\n\n**SETTER** - It's done in the setter because we then transfer it to the variable. This is later transferred to the database in the variable.\n\n**GETTER** - We use the getter to call it anywhere, e.g. an output on the page.\n\n\u003e Setter can be use to harmless incoming data.\n\n```php\n    /**\n     *\n     * @param string $email\n     */\n    public function setEmail(string $email = '')\n    {\n        // Add extra check before set\n        if (is_string($email) \u0026\u0026 strlen($email) \u003e 0 \u0026\u0026 strlen($email) \u003c= 255) {\n            $this-\u003eemail = str_replace('@', ' _*_ ', $email);\n            $this-\u003eemail = htmlspecialchars(strip_tags($this-\u003eemail));\n            // Use more masks...\n        }\n    }\n\n    public function getEmail()\n    {\n        return (string) $this-\u003eemail;\n    }\n```\n\n## VALIDATOR\n\nThe validators check whether the incoming data is also valid. We put checks there so we don't have to write one over and over again.\n\n\u003e Validator can use to check before set incoming data\n\n```php\n    /**\n     *\n     * @param string $email\n     *\n     * @see http://php.net/manual/de/filter.examples.sanitization.php\n     */\n    public function validateEmail(string $email = '')\n    {\n        $email = filter_var($email, FILTER_SANITIZE_EMAIL);\n        if (empty($email) or $email == '') {\n            $this-\u003eaddError('Please enter a E-Mail-Address');\n        } else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {\n            $this-\u003eaddError('This E-Mail-Address is invalid');\n        } else if (strlen($email) \u003c $this-\u003eminTextLength) {\n            $this-\u003eaddError(sprintf('The email should be at least %d characters long.', $this-\u003eminTextLength));\n        }\n        // Add more checkpoints...\n    }\n```\n\n## MODEL USAGE EXAMPLE\n\n```php\n    // OTHER CODE\n\n    public function contactAction(array $params = [])\n    {\n        $smailer = new SM();\n\n        // EXAMPLE USE OF A MODAL\n        /**\n         * Contact model instance\n         * Call from class.ContactModel.php\n         */\n        $contact = new C();\n        $contact-\u003esetCsrf(); // Create csrf token for form in template\n        // If contact form send\n        if (isset($_POST[\"contact\"])) {\n            // Validate all fields in validator\n            $contact-\u003evalidateByArray($_POST);\n            // Is valid ?\n            if ($contact-\u003eisValid()) {\n                // Set all data to User modal\n                $contact-\u003esetByArray($_POST);\n                /**\n                 * Save user in db\n                 * Call from class.UserModel.php\n                 */\n                if ($contact-\u003esaveObject()) {\n                    if ($smailer-\u003esendMail($contact-\u003egetEmail(), 'Thanks for contact', 'We have received your contact message')) {\n                        $contact-\u003eaddSuccess('Mail send thanks for contact us');\n                        $contact-\u003ecleanCsrf(); // Clean csrf token on success\n                    } else {\n                        $contact-\u003eaddError('Mail not send, please try again');\n                    }\n                }\n            }\n        }\n\n    // OTHER CODE\n```\n\n# VIEW\n\nThe view handles all template uses and context.\n\n```php\nclass IndexController extends AbstractController\n {\n    public function aboutAction(array $params = [])\n    {\n        V::addContext('data', array(\n            \"templates\" =\u003e array(\n                \"header\",\n                \"nav\",\n                \"about\",\n                \"footer\"\n            ),\n            \"meta-title\" =\u003e \"About\",\n            \"robots\" =\u003e \"index, follow, noodp\",\n            \"title\" =\u003e \"About us\",\n            \"description\" =\u003e \"About us.\",\n            \"nav-active\" =\u003e \"about\",\n            \"content\" =\u003e \"\u003ch2\u003eAbout\u003c/h2\u003e\u003cp\u003eAbout us.\u003c/p\u003e\",\n        ));\n\n        V::display();\n    }\n }\n```\n\nHere as example the `V::display()` searches for an index.php in core/tpl folder to load it.\n\nThe context `V::addContext('data', array)` add data `$data` with array `$data['templates']` for the template index.php to use it in there.\n\n```php\n\"templates\" =\u003e array(\n    \"header\",\n    \"nav\",\n    \"about\",\n    \"footer\"\n)\n```\n\nThe part of templates is for the second template we load in our index.php\n\nUse in templates core/tpl/index.php\n\n```php\n    if (isset($data['templates'])) {\n        // If templates loop it\n        foreach ($data['templates'] as $template) {\n            // Create template file path\n            $file = PROJECT_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . 'core/tpl' . DIRECTORY_SEPARATOR . $template . '.tpl.php';\n            // Check if exitst and load\n            if (file_exists($file)) {\n                require_once $file;\n            } else {\n                echo 'Tpl not found!';\n            }\n        }\n    }\n```\n\n# Roots\n\nIn the `root.php` there are path variables that have been defined. And should always be used for links or when loading a file.\n\n**The root.php uses functions from the core / func folder**\n\n\u003e It doesn't matter which folder you are in, whether on the server or locally.\n\u003e The `root.php` always determines the root (main) directory\n\n```php\nPROJECT_DOCUMENT_ROOT\n```\n\n```php\nDOCUMENT_ROOT\n```\n\n```php\nPROJECT_HTTP_ROOT\n```\n\n**USAGE EXAMPLE**\n\n```php\necho '\u003ca href=\"' . PROJECT_HTTP_ROOT . DIRECTORY_SEPARATOR . '/user/login/\"\u003eLink\u003c/a\u003e';\n```\n\n```php\nrequire_once DOCUMENT_ROOT . DIRECTORY_SEPARATOR . 'core/classes/';\n```\n\n# LANGUAGE\n\nEnglish is the first and main language, all other languages ever translated from that.\n\nTo translate string use the follwed functions:\n\n```php\n_e('Username'); // This echos the output\n```\n\nor use for later echo the output\n\n```php\n$variable = '# ' . __('Username');\necho $variable;\n```\n\nThe languages files are in `includes` folder e.g. `de_DE.json`\n\n```json\n{\n  \"Username\": \"Benutzername\",\n  \"E-Mail-Address\": \"E-Mail-Adresse\",\n  \"Message\": \"Nachricht\",\n  \"Send\": \"Senden\"\n}\n```\n\nYou can add other langauges, create another file with `tr_TR.json` or language you want.\n\n```json\n{\n  \"Username\": \"Kullanıcı adı\",\n  \"E-Mail-Address\": \"E-Posta Adresi\",\n  \"Message\": \"İleti\",\n  \"Send\": \"Gönder\"\n}\n```\n\nIf language file exists you can call the language via:\n\n**LANG USAGE EXAMPLE**\n\n`URL/de/contact/`\n\n`URL/tr/contact/`\n\n`URL/de/user/login/`\n\n`URL/tr/user/login/`\n\n# Settings\n\nThe database connections are defined in .env Create a `.env` file:\n\n## Database\n\nIn file `.env`\n\n```php\nDB_PREFIX=\nDB_HOST=localhost\nDB_PORT=3306\nDB_NAME=dbname\nDB_USER=root\nDB_PASS=password\n```\n\n## MAIL\n\nTo activate the mail function, download [PHPMailer](https://github.com/PHPMailer/PHPMailer) and create a folder `ext` in `core` dir `core/ext`.\nNow move your PHPMailer in the folder e.g. `core/ext/phpmailer-6.5.5` that's it.\n\nAdd your SMTP data in `.env`\n\n```php\nMAIL_HOST=\nMAIL_SMTP=tls\nMAIL_PORT=587\nMAIL_CHARSET=UTF-8\nMAIL_USERNAME=\nMAIL_PASSWORD=\nMAIL_MAIL_FROM=\nMAIL_ADMIN=\n```\n\n## DEBUG\n\nIn file `com.php` the common file.\n\n```php\ndefine('DEBUG', true);\n```\n\nIn file `settings.php` the settings file.\n\n```php\n/**\n * Debug setting\n */\ndefine('DEBUG_DISPLAY', true); // Screen errors on website\ndefine('DEBUG_LOG', true); // Log errors in file\ndefine('DEBUG_LOG_FOLDER', PROJECT_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'debug');\ndefine('DEBUG_LOG_FILE', PROJECT_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'debug/debug.log');\ndefine('DEBUG_DB_LOG', false); // Log errors in database\ndefine('DEBUG_MAIL_LOG', true); // Send errors per mail\ndefine('DEBUG_ADMIN_MAIL', ''); // Send errors to this email\n```\n\n# CORE\n\nThe core folder is to use for help with e.g. logging, session, js, templates, css, less etc.\n\n/classes\n\n/css\n\n/debug - Debug log files was generated here\n\n/ext\n\n/func - Functions to load fast and overall\n\n/img\n\n/js\n\n/less\n\n/tpl\n\n# ToDos\n\n- [ ] Expanding the admin area\n- [ ] Create Forgot password reset with auth email\n- [ ] Override internal session handlers\n- [ ] Create command for scaffold controller and models\n- [ ] Add bundler and co webpack, typescript etc.\n- [ ] Add composer for paypal etc.\n\n# Attention\n\nThis one should not use in a real environment but unfortunately there is also something in real environments.\n\n# ISSUE\n\nPlease use the issue tab to request a:\n\n* Bug\n* Feature\n\nChoose template and report a bug or feature you want [issues](https://github.com/prod3v3loper/php-mvc-professional/issues).\n\n# CONTRIBUTE\n\nPlease read the [contributing](https://github.com/prod3v3loper/php-mvc-professional/blob/master/.github/CONTRIBUTING.md) to contribute.\n\n# VULNERABILITY\n\nPlease use the Security section for privately reporting a [vulnerability](https://github.com/prod3v3loper/php-mvc-professional/security).\n\n# Authors\n\n**[prod3v3loper](https://www.prod3v3loper.com)** - _All works_\n\n# License\n\n[MIT](https://github.com/prod3v3loper/php-mvc-professional/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprod3v3loper%2Fphp-mvc-professional","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprod3v3loper%2Fphp-mvc-professional","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprod3v3loper%2Fphp-mvc-professional/lists"}