PHPackages                             aliasio/swiftlet - 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. aliasio/swiftlet

AbandonedArchivedLibrary

aliasio/swiftlet
================

Quite possibly the smallest MVC framework you'll ever use.

4196871PHP

Since May 21Pushed 8y ago1 watchersCompare

[ Source](https://github.com/AliasIO/Swiftlet)[ Packagist](https://packagist.org/packages/aliasio/swiftlet)[ RSS](/packages/aliasio-swiftlet/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Swiftlet [![Build Status](https://camo.githubusercontent.com/63fdea303f61a3cf07616720cea5fe2d64e6cc639835db6f575d09a50bccc0f6/68747470733a2f2f7472617669732d63692e6f72672f416c696173494f2f53776966746c65742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/AliasIO/Swiftlet)
========================================================================================================================================================================================================================================================================================

[](#swiftlet-)

[Swiftlet](http://swiftlet.org/) is quite possibly the smallest [MVC](http://en.wikipedia.org/wiki/Model-view-controller) framework you'll ever use. And it's swift.

*Licensed under the [MIT license](http://www.opensource.org/licenses/mit-license.php).*

Buzzword compliance
-------------------

[](#buzzword-compliance)

✔ Micro-Framework
✔ Loosely coupled
✔ Unit tested
✔ Namespaced
✔ Pluggable
✔ [Composer](https://getcomposer.org)
✔ [PSR-4](http://www.php-fig.org/psr/psr-4)
✔ PHP7
✔ MVC
✔ OOP

✘ ORM

Installation
------------

[](#installation)

- Clone (or download and extract) Swiftlet into a directory on your PHP supported web server.
- Having [Composer](https://getcomposer.org) installed, run `composer dump-autoload`.

Getting started: controllers and views
--------------------------------------

[](#getting-started-controllers-and-views)

Let's create a page. Each page consists of a controller and at least one view.

The controller does most of the work; views should be limited to simple presentation logic (loops and switches).

**Controller `src/HelloWorld/Controllers/Foo.php`**

```

```

The controller can set variables directly on the view. Values are automatically made safe for use in HTML, use `$this->get('variable', false)` on values that should be treated as code.

You can now view the page by navigating to `http:///foo` in your web browser!

If you get a "404 Not Found" you will need to enable rewrites in the web server configuration. Alternatively you can navigate to `http://?q=foo`.

*Swiftlet can be invoked from the command line (e.g. to run cron jobs). Simply run `php public/index.php -q foo`.*

Routing
-------

[](#routing)

Notice how you can access the page at `/foo` by simply creating a controller named `Foo`. The application maps URLs to controllers, actions and arguments.

Consider this URL: `/foo/bar`

In this case `foo` becomes the name of the controller and view and `bar` the name of the action. Actions are public methods on the controller class.

You can specify a different view for an action using `$this->view->setName()`. The view name is a filename relative to the `src\\views` directory, without the `.php` suffix.

If the controller or action is not specified they default to `index` (`/`will call `index()` on `\HelloWorld\Controller\Index`).

Underscores in the controller name are translated to directory separators, so `/foo_bar` will point to `src/HelloWorld/Controllers/Foo/Bar.php`.

Dashes in routes are ignored; `/foo-bar/baz-qux` calls `bazqux()` on `\HelloWorld\Controllers\Foobar`.

**Custom routes**

Automatic routing is convenient but more granular control is often desirable. In these cases custom routes can be defined.

A route maps a URL to an action (method).

URL segments can be replaced with a "wildcard" placeholder (a variable name prefixed with a colon). This value becomes available for use in the controller.

Consider this route: `bar/:qux`

Navigating to `/bar/something` matches this route. The value of `$args['qux']` becomes `something`.

```
