{"id":15578320,"url":"https://github.com/milesq/nyxt","last_synced_at":"2025-07-03T11:03:49.313Z","repository":{"id":45063635,"uuid":"332468539","full_name":"Milesq/nyxt","owner":"Milesq","description":"Simple and modern PHP framework","archived":false,"fork":false,"pushed_at":"2022-01-11T16:23:38.000Z","size":57,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-29T07:29:15.382Z","etag":null,"topics":["backend","framework","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Milesq.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-24T14:21:17.000Z","updated_at":"2021-03-20T13:05:16.000Z","dependencies_parsed_at":"2022-09-23T10:24:03.523Z","dependency_job_id":null,"html_url":"https://github.com/Milesq/nyxt","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Milesq/nyxt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milesq%2Fnyxt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milesq%2Fnyxt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milesq%2Fnyxt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milesq%2Fnyxt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Milesq","download_url":"https://codeload.github.com/Milesq/nyxt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milesq%2Fnyxt/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263314103,"owners_count":23447291,"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":["backend","framework","php"],"created_at":"2024-10-02T19:08:44.058Z","updated_at":"2025-07-03T11:03:49.283Z","avatar_url":"https://github.com/Milesq.png","language":"PHP","readme":"# Nyxt - modern \u0026 simple PHP framework\r\n\r\n## Installation\r\n\r\nYou use this framework by [composer](https://getcomposer.org/)\r\n\r\n`composer require milesq/nyxt`\r\n\r\n## Out of the box\r\n\r\nWhat is included in this package?\r\n\r\n-   Routing based on file system (custom 404, public directory)\r\n-   Twig template engine\r\n-   Form validation based on rakit/validation\r\n-   Simple a'la ORM to help you manage your database (based on clancats/hydrahon)\r\n\r\n## Using\r\n\r\nCheck our `examples/` directory\r\n\r\n### Before start\r\n\r\nNyxt have a small boilerplate. You must redirect all requests (except request which starts from `/public`) to index.php\r\n\r\nExample configuration for Apache\r\n\r\n```apache\r\nRewriteEngine On\r\n\r\nRewriteRule ^(app|dict|ns|tmp)\\/|\\.ini$ - [R=404]\r\n\r\nRewriteCond %{REQUEST_FILENAME} !-l\r\nRewriteCond %{REQUEST_FILENAME} !-f\r\nRewriteCond %{REQUEST_FILENAME} !-d\r\nRewriteRule ^(?!public/)(.+)$ index.php [L,QSA]\r\nRewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]\r\n```\r\n\r\nNow you can simply run framework from `index.php`\r\n\r\n```php\r\n\u003c?php\r\nrequire_once './vendor/autoload.php';\r\n\r\n$framework = new \\Nyxt\\Base;\r\n$framework-\u003erun();\r\n```\r\n\r\nThen create a folder named `controllers`.\r\nThis directory is the place for your routes.\r\nInside controller files you must declare class\r\ncalled `Handler` which extends from `\\Nyxt\\Controller`.\r\nThis class should have public handle function which will\r\nbe invoked when someone sends a request to your endpoint.\r\n\r\nExample of handler\r\n\r\n```php\r\n\u003c?php\r\nclass Handler extends \\Nyxt\\Controller {\r\n    public function handle() {\r\n        // There you can handle request\r\n        echo 'URL is: /';\r\n    }\r\n}\r\n```\r\n\r\n### Routing\r\n\r\nRouting is based on file system and inspired by [Nuxt](https://nuxtjs.org/)\r\n\r\nThere is a few rules you need to know to create routes\r\n\r\n-   `index.php` will take control over `/` path\r\n-   `something.php` can be achieved by `/something`\r\n-   `create.php` inside `user` can be achieved by `/user/create`\r\n-   you can add path parameters (slug) by prepend name of slug with `_`.\r\n\r\n    For example `controllers/user/_id.php` can be achieved by `/user/what-ever`\r\n    You have access to slug parameters by handler object like that: `$this-\u003eid`\r\n\r\nFor the following file structure, the following paths will be available:\r\n\r\n```\r\n|   .htaccess\r\n|   index.php\r\n|\r\n\\---controllers\r\n    |   index.php               /\r\n    |\r\n    \\---user\r\n        \\---_id\r\n                create.php      /user/what-ever/create\r\n                _action.php     /user/what-ever/name-of-action\r\n```\r\n\r\nCheck `examples/routing` for more tips\r\n\r\n### Templates\r\n\r\nInside `templates/`directory you can place\r\ntwig templates, nextly you can render\r\nthem inside controller by `$this-\u003erender($name, $parametersAsAssocTable)`\r\n\r\n**Important** Remember to set environment\r\nvariable `NYXT_MODE` to production on deploy server.\r\nIn development mode, cache is not used.\r\n\r\nYou can set template params through for a few ways\r\nE.g.\r\n\r\n```php\r\nclass Handler extends \\Nyxt\\Controller {\r\n    public function handle() {\r\n        // You can declare template arguments like:\r\n        $this-\u003eby_property = \"hello\";\r\n        $this-\u003ereset();\r\n        $this\r\n            -\u003esetByMethod(\"hello\")\r\n            -\u003esetChainMethod(\"world\")\r\n            -\u003eunset('chainMethod');\r\n\r\n        $this-\u003erender('index', ['by_arg' =\u003e 1]);\r\n    }\r\n}\r\n```\r\n\r\n### Validation\r\n\r\nEvery handler can declare `validate` method.\r\nThe method will be invoked with `$v`\r\nparameter which is an instance of `\\Rakit\\Validation\\Validator`.\r\nCheck out [https://github.com/rakit/validation](https://github.com/rakit/validation)\r\n\r\nThe `validate` method must tell Next if the validation passed\r\nvia return boolean or string.\r\n\r\n### Error 404 - not found\r\n\r\nYou can apply your own 404 page by add `[error].html`\r\ntemplate or `404.html` in public directory\r\n\r\n### Using DB\r\n\r\nORM is based on clancats/hydrahon,\r\nso check out [docs](https://clancats.io/hydrahon/master/)\r\nand `examples/orm`\r\n\r\nTo create a model, you need to create a file\r\nnamed which is a singular form of the db table.\r\n\r\nExample model:\r\n\r\n```php\r\n\u003c?php\r\nclass Bike extends \\Nyxt\\Model {\r\n    var array $__columns = ['position', 'docked']; # these columns will be used in select and create methods\r\n\r\n    public function docked() {\r\n        return $this-\u003efindByDocked(true);\r\n    }\r\n}\r\n```\r\n\r\nHow can we use this model?\r\n\r\nWhen `Handler` class is decorated with `#[nyxt('orm')]`\r\nevery model will be injected to handler\r\n\r\n```php\r\n#[nyxt('orm')]\r\nclass Handler extends \\Nyxt\\Controller {\r\n    function handle() {\r\n        $this-\u003ebikes-\u003edocked()-\u003ewhere('id', '\u003e', 3)-\u003eget();\r\n    }\r\n}\r\n```\r\n\r\nTo learn how exactly can u build queries take a look for hydrahon docs\r\n\r\n#### **Important**\r\n\r\nNow you may be asking \"how does Nyxt connect to the database?\"\r\n\r\nAnswer: If your app is using db, you must change index.php a little and provide db connector as the first argument of constructor of \\Nyxt\\Base\r\n\r\nE.g.\r\n\r\n```php\r\n$framework = new \\Nyxt\\Base(function() {\r\n    return new PDO(\"mysql:host=localhost;dbname=test\", \"username\", \"pass\");\r\n});\r\n```\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilesq%2Fnyxt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilesq%2Fnyxt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilesq%2Fnyxt/lists"}