Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/plumdog/skeleton

A toy PHP micro-framework
https://github.com/plumdog/skeleton

Last synced: about 1 month ago
JSON representation

A toy PHP micro-framework

Awesome Lists containing this project

README

        

Skeleton Micro-Framework
========================

Sample index.php file:
```php
'MyApp\Index',
'/add' => 'MyApp\Add',
'/edit' => 'MyApp\Edit',
'/api' => 'MyApp\API');
SkeletonHandler::handle($routes);
```

Where MyApp is a namespace that can be autoloaded.

The classes that you route to (ie, the values in the `$routes` array
above) should extend `SkeletonRequestHandler` and override its
`handle($request)` method. Here, you should use information from the
request, ie via `$request->post()`, `$request->get()` and do things
using `$request->db()` and then return a SkeletonResponse object.

Simple Example
--------------
```php
db()->prepare("SELECT * FROM items;");
$statement->execute();
return new SkeletonResponse($request, array('items' => $statement), 'index');
}
}
```

More Complex Example
--------------------
```php
get('id');

$statement = $request->db()->prepare("SELECT * FROM items WHERE id = :id;");
$statement->execute(array('id' => $id));
$item = $statement->fetch();

if($item === FALSE) {
return SkeletonResponse::error404($request, 'Item not Found');
}

$form = array('name' => '');

if($request->post()) {
$statement = $request->db()->prepare('UPDATE items SET name = :name WHERE id = :id;');
$statement->execute(
array('id' => $id,
'name' => $request->post('name')));
$request->redirect();
} else {
$form['name'] = $item['name'];
}

return new SkeletonResponse($request, array('form' => $form), 'form');
}
}
```

Views
=====

By default, we look in a directory called `views` in the webroot for
`.html` files. You can change where we look by setting `$VIEW_DIR` in
the config. For example:

```php
new SkeletonResponse($request, array('items' => $statement), 'index');
```

Will look for file called `index.html` in the views directory and try
to render it. When rendering, we will have access to a variable called
`$items` which will be set to whatever $statement is.

We only have one-level of template inheritance. You should create a view called `template.html` which should contain the line:

```php

```

This is where the inner view will appear. Eg:

```php


=htmlspecialchars($title)?>



=htmlspecialchars($title)?>