femtopixel/nano-framework

0.7.0 2022-01-30 17:44 UTC

This package is auto-updated.

Last update: 2024-11-02 17:06:48 UTC


README

Caution

As-of 2021, this product does not have a free support team anymore. If you want this product to be maintained, please support my work.

Note

(This product is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addition to maintenance and stability there are many desirable features yet to be added.)

logo

Nano Framework

Build Status Latest Stable Version Minimum PHP Version Scrutinizer Code Quality Code Coverage License PayPal donation Buy me a coffee Buy me a coffee

Nano is a simple stupid framework, really easy to handle, and really efficient.

It only implements the C part (Controller) of the MVC design pattern which allows developers to use any other existing library for others parts

Installation

composer require femtopixel/nano-framework

Bootstrap

all your request can be redirected to your bootstrap (assuming index.php)

<?php
require_once ('vendor/autoload.php');
$nano = new \Nano\Framework();
$nano->dispatch();

That's all!

How it works?

With that on, you can now access to your pages like this :

http://mysite.tld/ <controller>/<action>

And it will load the class \Project\Controller\<controller>::<method><action>Action

You can easily configure your namespace, controller package and action suffix!

<method> represents the HTTP method used (usually get but you can use post/update/delete etc...). This is optional.

Either <controller> or <action> are optional and considered as 'index' if not defined.

Therefore

Parameter Matching

Since 0.6.0, you can use "Parameter Matching"

Simply activate it when dispatching :

require_once ('vendor/autoload.php');
$nano = new \Nano\Framework();
$nano->setParameterMatching()->dispatch();

And then you'll be able to use it like this :

<?php
namespace \Project\Controller;

class MyAwesomeController
{
    public function getHelloAction($age, $name)
    {
        echo "Hello $name, I'm {$age}yo"; //please, use this code for test only
    }
}

and call http://mysite.tld/myawesomecontroller/hello?name=World&age=900 to display "Hello World, I'm 900yo" !