PHPackages                             coreyolson/framework - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. coreyolson/framework

ActiveLibrary[Framework](/categories/framework)

coreyolson/framework
====================

A minimalist PHP framework

0.9.9(5y ago)04MITPHPPHP &gt;=7.0.0

Since Jan 23Pushed 5y ago1 watchersCompare

[ Source](https://github.com/coreyolson/framework)[ Packagist](https://packagist.org/packages/coreyolson/framework)[ RSS](/packages/coreyolson-framework/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Framework
=========

[](#framework)

A Minimalist PHP Framework
--------------------------

[](#a-minimalist-php-framework)

Designed to be lightweight, fast and easy to use. Provides the bare essentials for a modern website; e.g., simple request routing to controllers which can then go on to invoke models or views as required. A minimalist PHP 7.0+ framework.

Getting Started
===============

[](#getting-started)

All requests routed through *index.php* to a controller. Application and framework logic is in the **application** folder. Sub-folders are labeled: controllers, helpers, libraries, models and views within the same main **application** folder.

### Quick Installation

[](#quick-installation)

No setup required. **mod\_rewrite** optional, but ideally **enabled**. All requests go through *public/index.php*. Modify *public/index.php* as needed. Without mod\_rewrite URLS are: */index.php/controller/method/param1/param2/*

##### Installation using PHP Composer:

[](#installation-using-php-composer)

```
composer create-project coreyolson/framework folder

```

##### Suggested Rewrite Rules:

[](#suggested-rewrite-rules)

```
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond \$1 !^(.*\..*) [NC]
RewriteRule ^(.*)$ ./index.php/\$1 [L]

```

### Structuring a Website or Web Application

[](#structuring-a-website-or-web-application)

Routing logic goes in **controllers**, application logic in **models**, and **views**contain templates. Alternative routing (i.e., including *Framework.php* via another file is possible, and) still allows access to libraries, helpers and views.

Routing
=======

[](#routing)

The framework routes URLs via {controller}/{action}/{param1}/{param2}. Printing internal the method `f::info()` offers more insights. The default controller is *home.php* with **index**as the default action/method, and can be changed. The framework looks for `before_{method}()`and `after_{method}()` respectively. These can be changed by passing your desired preferences to `framework::index('home/index', 'before/after');` within *public/index.php*.

### GET example.com/project/list

[](#get-examplecomprojectlist)

Routes to the **project.php** controller, or *404 error if controller does not exist.*

- Runs the `get()` method if it exists
- Runs the `before()` method if it exists
- Runs the `get_before()` method if it exists
- Runs the `before_list()` method if it exists
- Runs the `before_get_list()` method if it exists
- Runs the `get_list()` method, or *404 error if method does not exist.*
- Runs the `after_get_list()` method if it exists
- Runs the `after_list()` method if it exists
- Runs the `get_after()` method if it exists
- Runs the `after()` method if it exists

Get internal Framework and routing information by printing `f::info()`.

Basic Usage
===========

[](#basic-usage)

Using `f::method()` has a slight performance penalty, and is provided for convenience during development. For the best performance, access classes and methods using fully qualified names; e.g., `\helpers\arr::keys();` for the Array Helper.

##### Auto-load any helper or library

[](#auto-load-any-helper-or-library)

```
f::class()->method();                  // f::arr(), f::benchmark(), f::page(), f::file()

```

##### Using a Controller, Model, Helper or Library

[](#using-a-controller-model-helper-or-library)

```
f::controller('home')->get_index();    // controllers\home::get_index();
f::model('template')->demo();          // models\template::demo();
f::helpers('arr')->keys();             // helpers\arr::keys();
f::library('benchmark')->mark();       // libraries\benchmark::mark();

```

##### Using a view

[](#using-a-view)

```
echo f::view('filename');              // view::echo('filename');

```

##### Using a dynamic view

[](#using-a-dynamic-view)

```
f::view('filename', ['var' => 'val']);	// view::return('filename', ['var' => 'val']);

```

Advanced Usage
==============

[](#advanced-usage)

Add custom routes in *public/index.php* as needed; e.g., `route::verb('/{pattern}', function () { //code });` Any HTTP verb may be used, even non-standard verbs. Two framework-specific verbs `route::any` and `route::port` have unique functionality for matching *any* HTTP verb, and immediately running framework routing upon matching *port* requests.

**GET request to example.com/users/**

```
route::get('/users/', function () {
    //code
});                                             // Continues processing

```

**POST request to example.com/users/edit/**

```
route::post('/users/edit/', function () {
    //code
}, true);                                       // Stops processing on TRUE

```

**PORT request to example.com/internals/**

```
route::port('/internals/', function () {});     // Switches to framework:index() routing

```

### Cron Configuration

[](#cron-configuration)

The framework can function as a cron dispatcher; however, a cronjob still needs to be configured on the web server. The following runs the framework cron dispatcher every minute; which looks in the \_application/controllers/*cron* folder for scheduled controllers to run. Use the framework's scheduling options to configure the desired time and frequency.

```
(crontab -l 2>/dev/null; echo "# * * * * * wget https://localhost/?_cron -O /dev/null") | crontab -

```

*Note: Framework must be able to write to the *storage/* folder for Crons to work; or, you can manually create a writeable file at \_storage/.*cron.json* ; adjust if using a different \_cron configuration/folder.*

##### An example Cron task / controller within Framework

[](#an-example-cron-task--controller-within-framework)

```
