forked from zer.ooo/web
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
1.3 KiB
Markdown
104 lines
1.3 KiB
Markdown
9 years ago
|
# Glim
|
||
|
|
||
|
Adding more glamour to Slim
|
||
|
|
||
|
# What is it?
|
||
|
|
||
|
Glim HSVM model build around Slim, Propel and Twig.
|
||
|
|
||
|
# HSVM
|
||
|
|
||
|
I totally just made that up but it stands for **H**andler **S**ervice **V**iew **M**odel
|
||
|
|
||
|
## Handler
|
||
|
|
||
|
A handler is like a controller but only handles one request, every route has it's own handler.
|
||
|
|
||
|
An example handler would look like
|
||
|
|
||
|
```php
|
||
|
<?php
|
||
|
|
||
|
namespace Eater\Glim\Handler;
|
||
|
|
||
|
class Login extends Main
|
||
|
{
|
||
|
function handle()
|
||
|
{
|
||
|
$user = this->get('user');
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
$user = $user->login($this->post('username'), $this->post('password'));
|
||
|
|
||
|
if ($user === false) {
|
||
|
return "Login failed";
|
||
|
} else {
|
||
|
return "Welcome, {$user->name}";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
## Service
|
||
|
|
||
|
A service is an class exposing several functions around a certain subject
|
||
|
|
||
|
for example here we have the user service
|
||
|
|
||
|
```php
|
||
|
<?php
|
||
|
|
||
|
namespace Eater\Glim\Service;
|
||
|
|
||
|
class User extends Main
|
||
|
{
|
||
|
function login($username, $password)
|
||
|
{
|
||
|
if ($username == "4" && $password == "2") {
|
||
|
$user = new \stdClass();
|
||
|
$user->name = "Towel";
|
||
|
|
||
|
return $user;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
## View
|
||
|
|
||
|
The view, written in [twig](http://twig.sensiolabs.org)
|
||
|
|
||
|
## Model
|
||
|
|
||
|
The model, generated by [propel](http://propelorm.org)
|