Skip to content
/ enginr Public

(AT REST) A lightweight PHP solution for easily creating web applications.

License

Notifications You must be signed in to change notification settings

Enginr/enginr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enginr v1.0.*-alpha

GitHub PHP RELEASE

Enginr is a very lightweight micro-framework for writing Web applications or API quickly.

Strongly inspired by Node.js (and more particularly by its micro-framework Express.js), learning how to use it is therefore very simplified if you know these technologies.

The biggest difference is the use of $ for your variables... Yey...

🚩 Note : This guide is for the alpha version. Many changes can be made in the near future.

Getting started

This section will show you how to create your first Enginr application.

Installation

It is strongly recommended to use composer to work with Enginr.

Using composer

composer require enginr/enginr:v1.0.*-alpha

Using git

git clone https://github.com/Enginr/enginr.git \
cd enginr \
composer update

Hello world

Using Manager (prototype)

To easily create an Enginr project, you can use the manager.
To use it, start by installing it globally on your machine via composer.

composer global require enginr/manager:dev-master

Once the manager is installed. We will create our first project... For this guide, I will call it myProject. But you can give it any name you want !

enginr create myProject

You will have to follow a short interactive guide, then once done, your project will be generated !

Once the generation is complete, go (still in your terminal) to the folder of your project (its name corresponds to the name you gave to your project), then launch the server.

cd myProject \
php app.php

If your server has started correctly, go to your browser, then enter the address of your server.
Note : The alpha version of the manager will have given you the address localhost:8000.

You should see the Enginr welcome page !

From scratch

The most existing moment... 😁
Let's create our first application !

1. Create a new project

mkdir myApp \
cd myApp

2. Deploy Enginr to the project

See installation guide.

3. Create the application file

You could named your application file like you want. By convention, I will use app.php for this guide...

touch app.php

This will be the main file of your application.
By analogy, I would say that it is in a way the "motherboard" of your application.
It will be in this file that you will define the configuration of your server and that you will add your different modules.

4. Let's code !

Now, let's define what our application needs a minimum to work.
In your app.php file, enter the following code.

require 'vendor/autoload.php';

$app = new \Enginr\Enginr();

$app->get('/', function($req, $res) {
	$res->send('Hello world !');
});

$app->listen('127.0.0.1', 3000);

💡 Need some explanations ?

OK. First, we need to instanciate Enginr :

$app = new \Enginr\Enginr();

After that, the minimum to do is to declare our first route. Here, we listening for the root route of our website.

$app->get('/', ...

At the same time, we specify the controller (the action we choose to do) when a user goes to this route ...

$app->get('/', function($req, $res) {
	$res->send('Hello world !'); // Send 'Hello world !' to the client
});

Now, your application need an host and a port to listening connections ...

$app->listen('127.0.0.1', 3000);

5. Run the server

For our application to work, we need to start it.
To do this, let's go to our terminal (to the root location of our project), then launch the application.

php app.php

6. Test our app

Open our favorite browser, and enter the host:port of our app. Normaly, we get a great :

Hello world !

That's it ! 🍻

About

(AT REST) A lightweight PHP solution for easily creating web applications.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages