{"id":18289864,"url":"https://github.com/prahladyeri/minimal-mvc","last_synced_at":"2025-04-05T09:31:49.316Z","repository":{"id":242185002,"uuid":"808913695","full_name":"prahladyeri/minimal-mvc","owner":"prahladyeri","description":"A frugal and utilitarian PHP micro-framework with basic routing and templating capabilities","archived":false,"fork":false,"pushed_at":"2024-06-29T02:15:06.000Z","size":118,"stargazers_count":15,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T03:30:35.068Z","etag":null,"topics":["framework","minimal","mvc","php","routing","templates"],"latest_commit_sha":null,"homepage":"","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/prahladyeri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-01T06:27:29.000Z","updated_at":"2025-01-07T11:10:32.000Z","dependencies_parsed_at":"2024-06-09T12:34:30.541Z","dependency_job_id":"44bbe23b-0e23-4dca-abb5-49451a650af5","html_url":"https://github.com/prahladyeri/minimal-mvc","commit_stats":null,"previous_names":["prahladyeri/minimal-mvc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prahladyeri%2Fminimal-mvc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prahladyeri%2Fminimal-mvc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prahladyeri%2Fminimal-mvc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prahladyeri%2Fminimal-mvc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prahladyeri","download_url":"https://codeload.github.com/prahladyeri/minimal-mvc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247318315,"owners_count":20919457,"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","minimal","mvc","php","routing","templates"],"created_at":"2024-11-05T14:08:36.633Z","updated_at":"2025-04-05T09:31:48.162Z","avatar_url":"https://github.com/prahladyeri.png","language":"PHP","funding_links":["https://www.patreon.com/prahladyeri","https://paypal.me/prahladyeri"],"categories":[],"sub_categories":[],"readme":"![license](https://img.shields.io/github/license/prahladyeri/minimal-mvc.svg)\r\n![last-commit](https://img.shields.io/github/last-commit/prahladyeri/minimal-mvc.svg)\r\n[![patreon](https://img.shields.io/badge/Patreon-brown.svg?logo=patreon)](https://www.patreon.com/prahladyeri)\r\n[![paypal](https://img.shields.io/badge/PayPal-blue.svg?logo=paypal)](https://paypal.me/prahladyeri)\r\n[![follow](https://img.shields.io/twitter/follow/prahladyeri.svg?style=social)](https://twitter.com/prahladyeri)\r\n\r\n**minimal-mvc** is a humble attempt to de-cruft and de-bloat the scene of web frameworks. It's a specialized micro framework for following use cases or traits:\r\n\r\n1. Freelancers, students and hobbyists who want to experiment with PHP.\r\n2. Your app has simple CRUD workflow and just needs basic routing and templating capabilities of PHP.\r\n3. Your app is mostly frontend heavy (SPA, etc.) and uses PHP for very basic features like routing.\r\n4. You are developing a REST API.\r\n5. You find it unnecessary to optimize for hypothetical futuristic scaling.\r\n6. Not a huge fan of applying OOP everywhere.\r\n7. Generally prefer to work with core language capabilities than hand-holding of a heavy framework.\r\n\r\n**How to use minimal-mvc framework:**\r\n\r\nJust download this repo and use it to prototype your app. The core consists of only two PHP scripts which are required in index.php:\r\n\r\n- `core/router.php` - For routing capabilities.\r\n- `core/util.php` - For generic utility functions.\r\n\r\nIn `index.php`, you can handle basic routing easily like this:\r\n\r\n```php\r\nfunction index() {\r\n\techo \"\u003ch1\u003eIt Works!\u003c/h1\u003e\";\r\n};\r\n```\r\n\r\nThis is a very simple routing arrangement where each function inside index.php is a route with the `index()` function being the main or default route. For example, `/` routes to `index()`, `/api` routes to `api()`, etc.\r\n\r\n```php\r\nfunction api() {\r\n\techo \"\u003cp\u003ePattern Match!\u003c/p\u003e\"; // http://localhost/api/foo\r\n\techo \"\u003cp\u003eThe uri segments are :\".print_r(uri_segments(),true).\"\u003c/p\u003e\";\r\n};\r\n```\r\n\r\nYou can know the current HTTP method by `get_method()` utility function and get individual route segments using the `uri_segment()` utility function (such as 'api' in case of `uri_segment(1)` where route is `/api/foo/bar`). Similarly, `uri_segments()` returns an array consisting of all route segments.\r\n\r\nFor views/templates, you can use the load_template() utility function as shown in this built-in example:\r\n\r\n```php\r\nfunction testmvc() {\r\n\t$vars = [\"foo\"=\u003e'bar', 'title'=\u003e'Testing'];\r\n\tload_template('templates/dummy.php', $vars);\r\n};\r\n```\r\n\r\nThe template system works on a stereotype base template (`templates/base.php`) which can include all the frontend details like link and script tags to bootstrap, react, jquery, etc. And it should contain a placeholder called `$__contentfile` somewhere in the body section for the contents of \"child template\" (such as the built-in `templates/dummy.php` template) which is derived or inherited from the base template and directly passed in the `load_template()` utility function. In that child template, all variables you pass (`$vars` in this example) will be extrapolated for you to use. Note that we will not use any specific template language like `jinja` or `twig` as PHP itself is a template engine.\r\n\r\nIn addition to that, the framework also includes a static directory to store your static files like stylesheets, ECMA scripts, images, etc.\r\n\r\nOther useful utility functions are `base_url()` and `site_url()`. These are useful for resolving full url paths when your app is hosted inside a sub folder like `http://\u003csome-domain\u003e/subfolder` or when you want to resolve the actual url from a route such as \"foo/bar\". For almost everything else under the Sun, PHP is more than capable of handling whatever you throw at it.\r\n\r\nThe routing capability provided here is very basic, any further implementation will be a DIY. Other frameworks provide fancy routes like `/foo/bar/{slug}` and `/article/{locale}` which appears mind-blowing initially. But once you consider that PHP provides you a built-in called `$_SERVER['REQUEST_URI']` which you can parse yourself inside the `/foo/bar/` or `/article/` routes to get these yourself, that magic starts waning! To make things a bit easier, this framework provides you the shortcut utility function `uri_segment()` as mentioned earlier to determine these so called fancy variables:\r\n\r\n```php\r\necho uri_segment(3); // outputs the {slug} value or third segment in the URI\r\n```\r\n\r\n**What Next?**\r\n\r\nThe util.php is a work in progress and will keep improving with time. The idea is really that simple, PHP was originally built as a language that employed functions to manage its workflow (to a great extent, it still does), and minimal-mvc is also in the same spirit. If your app increases in complexity or scale, you can put the controller logic inside additional script modules and require them in index.php like this:\r\n\r\n```php\r\nfunction foo() {\r\n\trequire_once(\"controllers/foo_controller.php\");\r\n};\r\n```\r\n\r\nIt's upto you whether you name that folder controllers or something else, whether you use classes inside the script or plain old functions. As I said, there will be no hand holding!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprahladyeri%2Fminimal-mvc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprahladyeri%2Fminimal-mvc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprahladyeri%2Fminimal-mvc/lists"}