Giter Site home page Giter Site logo

fir's Introduction

GitHub issues

Fir Framework

Fir

Fir. A lightweight PHP MVC Framework.

The Fir framework started as micro-framework with the purpose of being used in private projects, with the strongest points being extremly fast and easy to use. Fir is not a replacement for professional frameworks, however if you want to quickly build a prototipe app, make a couple of AJAXed pages and do a couple of database calls, Fir should be a good option.

Features

Back-end

  • Extremely fast (3ms exec. time)
  • Extremely lightweight (30kb)
  • MVC pattern
  • Dynamic Routing (with clean URLs)
  • Helpers support (lazy loading)
  • Libraries support (lazy loading)
  • Middlewares support (lazy loading)
  • Composer support (lazy loading)
  • Language system (lazy loading)
  • Fully namespaced
  • PSR-2 coding style
  • CSRF protection for forms

Front-end

  • Dynamic page loading (AJAX)
  • jQuery included
  • Bootstrap included

Documentation

Requirements

Software Modules
PHP >=7 mbstring
Apache >=2 mod_rewrite
MySQL >=5

Installation

  1. Run composer create-project pricop/fir /your-project
  2. Import the fir.sql file into your database.
  3. Open the app/includes/config.php file, and update the values YOURDBUSER, YOURDBNAME, YOURDBPASS, https://localhost/your-project with your own information.

You can now access your website using the URL you defined in APP_PATH.


Controllers

Creating a new controller

  • Controllers can be created in the /app/controllers folder.
  • Controllers should extend the base Controller class, e.g: class Auth extends Controller {}.
  • Each controller must have a public method, called index, e.g: public function index() {}.

Loading a model

  • To load a new model, use the $this->model('Example') method.

Returning a view

  • To return a view, inside your methods you would return ['content' => $this->view->render($data, 'auth/register')], where $data is an array object which contains the data that's passed to the views, while 'auth/register' would be the view's path.

Routing

  • Routes are mapped based on the Controller's name and its public methods, when a public method is missing, it will automatically default to the index method of the controller.

Additional

  • You can access the current URL path inside controllers by using the $this->url property.
  • You can access language strings inside controllers by using the $this->lang property.

Example

namespace Fir\Controllers;

class Auth extends Controller
{
    public function index()
    {
        return ['content' => $this->view->render($data, 'auth/index')];
    }
    
    public function register()
    {
        return ['content' => $this->view->render($data, 'auth/register')];
    }
}

Models

Creating a model

  • Models can be created in the /app/models folder.
  • Models should extend the base Model class, e.g: class Auth extends Model {}.
  • You can access the database object by using the $this->db property.

Example

namespace Fir\Models;

class Auth extends Model
{
    public function get()
    {
        // SQL query here
    }
}

Views

Creating a view

  • Views can be created in the /public/theme/views folder.

Accessing data in views

  • The $data array object holds all the data that's passed from the Controllers.

Additional

  • You can escape strings in views using the e function, e.g: e('Example').
  • You can display messages stored in $_SESSION['message'] using the $this->message() method.
  • You can display a language string in views using the $this->lang('key') method.
  • You can render the csrf token input for your forms using the $this->token() method.
  • To view the full list of available helpers for views, see app/core/View.php.

Example

<?php
defined('FIR') OR exit();
?>

<?= e("Hello World") ?>

Wraping up

While this documentation could be more extensive, the code is well commented and most of the things you need to know can be found straight into the examples provided within the framework.

Happy coding.

fir's People

Contributors

pricop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.