Download the PHP package milesq/nyxt without Composer
On this page you can find all versions of the php package milesq/nyxt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nyxt
Nyxt - modern & simple PHP framework
Installation
You use this framework by composer
composer require milesq/nyxt
Out of the box
What is included in this package?
- Routing based on file system (custom 404, public directory)
- Twig template engine
- Form validation based on rakit/validation
- Simple a'la ORM to help you manage your database (based on clancats/hydrahon)
Using
Check our examples/ directory
Before start
Nyxt have a small boilerplate. You must redirect all requests (except request which starts from /public) to index.php
Example configuration for Apache
Now you can simply run framework from index.php
Then create a folder named controllers.
This directory is the place for your routes.
Inside controller files you must declare class
called Handler which extends from \Nyxt\Controller.
This class should have public handle function which will
be invoked when someone sends a request to your endpoint.
Example of handler
Routing
Routing is based on file system and inspired by Nuxt
There is a few rules you need to know to create routes
index.phpwill take control over/pathsomething.phpcan be achieved by/somethingcreate.phpinsideusercan be achieved by/user/create-
you can add path parameters (slug) by prepend name of slug with
_.For example
controllers/user/_id.phpcan be achieved by/user/what-everYou have access to slug parameters by handler object like that:$this->id
For the following file structure, the following paths will be available:
Check examples/routing for more tips
Templates
Inside templates/directory you can place
twig templates, nextly you can render
them inside controller by $this->render($name, $parametersAsAssocTable)
Important Remember to set environment
variable NYXT_MODE to production on deploy server.
In development mode, cache is not used.
You can set template params through for a few ways E.g.
Validation
Every handler can declare validate method.
The method will be invoked with $v
parameter which is an instance of \Rakit\Validation\Validator.
Check out https://github.com/rakit/validation
The validate method must tell Next if the validation passed
via return boolean or string.
Error 404 - not found
You can apply your own 404 page by add [error].html
template or 404.html in public directory
Using DB
ORM is based on clancats/hydrahon,
so check out docs
and examples/orm
To create a model, you need to create a file named which is a singular form of the db table.
Example model:
How can we use this model?
When Handler class is decorated with #[nyxt('orm')]
every model will be injected to handler
To learn how exactly can u build queries take a look for hydrahon docs
Important
Now you may be asking "how does Nyxt connect to the database?"
Answer: 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
E.g.
All versions of nyxt with dependencies
bramus/router Version ^1.5
twig/twig Version ^3.2
clancats/hydrahon Version ^1.1
icanboogie/inflector Version ^2.0