Transcript
Page 1: Flyr PHP micro-framework

Flyr – PHP micro framework

Page 2: Flyr PHP micro-framework

There are a lot of frameworks, each one with their particularities. There are really good frameworks like laravel, codeigniter, cakephp, etc.

Flyr wants to be easy, simple and extensible. The goal is develop a fast micro-framework which be so fast as user needs to develop applications.

Why try to remake validators, uploaders, orms and more software pieces if you can find them in github with great quality and well tested?

Then you can add those libraries with a package manager like composer in your flyr project.

Why another framework?

Page 3: Flyr PHP micro-framework

Flyr comes with a set of utilities:

- Router system with support for GET, POST, PUT and DELETE methods.

- Simple log component with email and file support.

- Http header manipulation.

- Cookies encryption.

- Simple cookie and session api.

- Easy multi-language component.

- Twig and php templates.

- Simple application skeleton for organize your project.

- Little mail sender support with PHPMailer.

What contains Flyr?

Page 4: Flyr PHP micro-framework

Installing flyr is as simple as creating a composer project or downloading the zip file inside the flyr github REPOSITORY that contains all packages needed to run your application.

Run the following command to start a new project(at the current moment):

> composer create-project “flyr/flyr”:“1.0.*@dev”

Or simply download Flyr.zip in https://github.com/SiroDiaz/Flyr.

Now you have installed a copy of Flyr framework and you are ready to start developing.

How to install Flyr?

Page 5: Flyr PHP micro-framework

You can design a REST API easily using four request methods: GET, POST, PUT and DELETE. Also, each route can contain parameters.

Finally you can pass a callback(anonym function) or the controller and method name. This last option would be better for organize your project.

To resume this part you will see a few lines of code to understand better all refered to routes.

Routes

Page 6: Flyr PHP micro-framework

Routes example

Page 7: Flyr PHP micro-framework

• Flyr also provides support for simple PHP templates (with tags <?php ?>) and Twig template engine.

• You can render templates with the render method.• But not only one template can be rendered for show in the browser, also you are able

to render multiple php or twig templates calling multiple times render method.

All templates are saved inside the folder app/views/ and all Twig templates are automatically cached.

Views

Page 8: Flyr PHP micro-framework

Views example

Page 9: Flyr PHP micro-framework

For developing the REST of APIs you will need to return in your response body a data type like JSON or XML and must be defined the response encoding as application/json or

text/xml for each data type.

You can set all response headers using the header->set method.

Maybe you need to remove headers like X-powered-by , redirect or send a response code.

It is simple and you can see the following examples using header object.

HTTP headers

Page 10: Flyr PHP micro-framework

HTTP headers example

Page 11: Flyr PHP micro-framework

Session and cookies have a new API for make many actions in the correct way like deleting sessions and cookies, encrypting cookies or prevent cookie access from the browser.

In the PHP cofiguration file (Flyr/Config/php_config.php) cookies and sessions are correctly cofigured for avoid main source of session hijack.

Cookies methods are: create, delete, deleteAll, set, get.

Session methods are: start, set, get, delete, deleteAll.

You can see the following examples:

Managing sessions and cookies

Page 12: Flyr PHP micro-framework

Cookies and sessions example

Session example

Cookie example

Page 13: Flyr PHP micro-framework

Other important object is the flyr loader. You can load helpers and language files. Helpers are files containing functions or classes to solve a specific group of problems. For example, you can create a file called string_helper.php that has some functions to manipulate strings.

In the following example you can see how to load a language file containing the seven days in Spanish:

Loader

Page 14: Flyr PHP micro-framework

Loading a language file example

A language file with an associative array style

Loading the language file named ‘days.php’ inside the language folder ‘es’

Page 15: Flyr PHP micro-framework

Thanks

To know more about Flyr micro-framework and read the full

documentation visithttps://github.com/SiroDiaz/Flyr

Fork and star the project


Top Related