2017 © Pedro Peláez
 

library frmwrk

A simple framework

image

kyu/frmwrk

A simple framework

  • Saturday, October 4, 2014
  • by kyubantai
  • Repository
  • 1 Watchers
  • 1 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Frmwrk

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., (*1)

Usage

Just include the autoload.php file (generated by composer), init the config and instantiate it!, (*2)

<?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 :, (*3)

  • 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:, (*4)

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., (*5)

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., (*6)

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., (*7)

<?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:, (*8)


<foreach var="array" as="value">
    Value: {{_value_}}
</foreach>


<foreach var="array" key="k" as="value">
    Key: {{_k_}}<br/>
    Value: {{_value_}}
</foreach>


<if cond="_myvar_ == 20">
    20
<elseif cond="_myvar_ > 50">
    > 50
<else>
    < 50 & != 20
</if>


{{_myvar_}}

/!\ It still is a prototype and will change!, (*9)

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., (*10)

Question?

If you have any questions or if you think there are missing information in this readme.md, please notice me., (*11)

The Versions

04/10 2014

dev-master

9999999-dev

A simple framework

  Sources   Download

MIT

by Bastien Nivet

02/10 2014

1.0.0.x-dev

1.0.0.9999999-dev

A simple framework

  Sources   Download

MIT

by Bastien Nivet