kyu / frmwrk
A simple framework
This package is not auto-updated.
Last update: 2025-06-17 07:57:55 UTC
README
Frmwrk is a simple and young framework. It's currently only composed of a View-Controller system (As soon as possible, model part will be included), but you can use your own database manager.
Usage
Just include the autoload.php file (generated by composer), init the config and instantiate it!
<?php require __DIR__ . '/../vendor/autoload.php'; $config = [ 'controllers' => __DIR__ . '/../app/Controllers/', 'views' => __DIR__ . '/views/', 'web' => __DIR__ ]; \Frmwrk\Engine::init($config); $instance = \Frmwrk\Engine::getInstance(); $instance->render();
Configuration
Configuration array has several parameters :
- controllers: It must contain the path to the controllers folder
- views: It must contain the path to the views folder
- default_controller: (default: 'index') It's the name of the default controller
- notfound: (default: 'notfound') It's the name of the controller which is loaded when the asked controller does not exists.
- pretty_url: (default: true) If enabled, you will use a clearer way to pass variables through url. (See next part for more details)
- web: It's the path of the web folder
Pretty URL
The pretty url feature is only used to simplify urls. Here are some samples:
http://domain.tld/CONTROLLER_NAME
http://domain.tld/CONTROLLER_NAME/VAR_NAME_1/VAR_VALUE_1
http://domain.tld/CONTROLLER_NAME/VAR_NAME_1/VAR_VALUE_1/VAR_NAME_2/VAR_VALUE_2/
ect...
The first parameter, called CONTROLLER_NAME, is the name of the controller you want to load.
The next parameters always works by pair. The first one will always be the name of the variable and the second one will be the value.
http://domain.tld/index/lang/fr/
will load the controller 'index' and send him the variable lang which contains 'fr'.
These variables are sent in the init() function of the current Controller.
<?php class index extends \Frmwrk\Controller { public function init($variables) { print_r($variables['_GET']); // Will display $_GET variables print_r($variables['_POST']); // Will display $_POST variables print_r($variables['_URL']); // Will display Pretty URL variables // ... } }
Templates
You can now use php as tags in your views! It's currently a prototype version of the template parser, but it works. Foreach, if/elseif/else and echo are available and here how to use them:
<!-- A simple foreach --> <foreach var="array" as="value"> Value: {{_value_}} </foreach> <!-- A key/value foreach --> <foreach var="array" key="k" as="value"> Key: {{_k_}}<br/> Value: {{_value_}} </foreach> <!-- A if --> <if cond="_myvar_ == 20"> 20 <elseif cond="_myvar_ > 50"> > 50 <else> < 50 & != 20 </if> <!-- Display a var--> {{_myvar_}}
/!\ It still is a prototype and will change!
What's next?
It's a good question, and I don't really know. The framework is updated every time I see that it's missing something. The most important feature is the database management, but there is also a real template system with cache management to do.
Question?
If you have any questions or if you think there are missing information in this readme.md, please notice me.