pricop / fir
Fir. A lightweight PHP MVC Framework.
Installs: 32
Dependents: 0
Suggesters: 0
Security: 0
Stars: 35
Watchers: 7
Forks: 12
Open Issues: 0
Type:project
pkg:composer/pricop/fir
Requires
- php: >=7.0.0
- ext-mbstring: *
This package is auto-updated.
Last update: 2025-01-04 01:38:29 UTC
README
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 prototype 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
Installation
- Run
composer create-project pricop/fir /your-project - Import the
fir.sqlfile into your database. - Open the
app/includes/config.phpfile, and update the valuesYOURDBUSER,YOURDBNAME,YOURDBPASS,https://localhost/your-projectwith 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/controllersfolder. - Controllers should extend the base
Controllerclass, 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$datais 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
indexmethod of the controller.
Additional
- You can access the current URL path inside controllers by using the
$this->urlproperty. - You can access language strings inside controllers by using the
$this->langproperty.
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/modelsfolder. - Models should extend the base
Modelclass, e.g:class Auth extends Model {}. - You can access the database object by using the
$this->dbproperty.
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/viewsfolder.
Accessing data in views
- The
$dataarray object holds all the data that's passed from the Controllers.
Additional
- You can escape strings in views using the
efunction, 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.