Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/jakobjohansson/kiwi

a minimalistic and lightweight blog framework for php
https://github.com/jakobjohansson/kiwi

blog blog-engine hobby-project in-development php

Last synced: about 1 month ago
JSON representation

a minimalistic and lightweight blog framework for php

Awesome Lists containing this project

README

        

# kiwi [![Packagist](https://img.shields.io/packagist/v/jakobjohansson/kiwi.svg)](https://packagist.org/packages/jakobjohansson/kiwi) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d91c9b74721a47e4a124bc5da221ac73)](https://www.codacy.com/app/jakobjohansson2/kiwi?utm_source=github.com&utm_medium=referral&utm_content=jakobjohansson/kiwi&utm_campaign=badger) [![StyleCI](https://styleci.io/repos/75422681/shield?branch=master&style=flat)](https://styleci.io/repos/75422681)

kiwi is a minimalistic and lightweight blog framework for php.

## Documentation
Kiwi can be installed via Composer:
```
composer create-project jakobjohansson/kiwi
```

### Configuration
Included in the package is a `.env.example` file, which should be renamed to `.env` and omitted from version control. It is a simple environment file containing fields for database settings, user settings and more general application settings. Kiwi will not run without this file.

After this is done, you should head to the */migrate* route to migrate the default SQL tables.

### Routes
Custom routes can be set in the `app/routes.php` file, pointing a route towards a controller and a target method:
```php
get('', 'PageController/index');
$router->get('post/{id}', 'PageController/show');
```

### Controllers
All controllers reside in the `app/Controllers` directory. An example controller is included with the following methods:
```php
Post::all()]);
}

/**
* Render a specific post page.
*
* @param Post $post
*
* @return void
*/
public function show(Post $post)
{
if (!$post) {
throw new HttpException("That post doesn't exist.");
}

View::render('post', ['post' => $post]);
}
```
Notice the type hinted *Post* parameter in the show method. It will be automatically injected when you provide a wildcard in your route!

#### Middleware
You can apply custom middleware by creating a `middleware()` method in your controller. It will run on every request directed towards the controller.

### Views
As seen in the example above, views can be requested from a controller method by stating `View::render($viewpath, $arrayOfData)`. The view path is relative to the `app/Views` folder, with a suffixed `.view.php` added at the end, meaning you can simply enter the file name.

### Templating
Kiwi supports templating similar to that of Laravel Blade:
```php


@foreach ($posts as $post)



{{$post->title}}



{{nl2br($post->body)}}


Written {{$post->created_at}}.

@endforeach

```
At the time of writing, the following directives are supported:
- if / elseif / else statements
- echo expressions
- foreach loops
- includes

### Validation
Validation is rather simple with kiwi. Simply access a form field using the `Input` class, which takes the field name as the first parameter and an array of rules as the second parameter:
```php
title = Input::field(
'title',
[
'required' => 'The title is required.',
'min:3' => 'The title needs to be atleast 3 characters long.',
]
);

$post->save();
```
The supported rules can be found in the `Rule` class. At the time of writing, the following rules are supported:
- min
- max
- required
- email
- url
- digits
- alpha

If validation fails, kiwi will redirect back with access to an `$errors` variable, containing all the data you need to display an informative error message!

## License
Kiwi is MIT licensed, meaning you are free modify and do as you wish with the code.