Small but Beautiful
Ik heb een vandaag een klein framework gemaakt die ik graag met jullie deel.
Small but Beautiful op Github met 'Hello World' applicatie.
Mochten er positieve reacties zijn, zal ik het in de scriptlib stoppen. (Om het goede voorbeeld te geven ;-) ). Alle negatieve (opbouwende) reacties zijn natuurlijk ook welkom.
Wat functionaliteiten:
- Dependency injection container
- Uitbreidbare views (layouts dus)
- View partials
- Routing. De route van het voorbeeld is: '/hello[/:name]'
- Fijn configureren in native PHP ;-)
- Alles in 1 bestand :D
- Wel mogelijkheid tot view-helpers, maar geen view-helpers
- (Soort van) OOP
- Geen ingewikkelde namespaces (wel een autoloader daarvoor)
- Goed aanpasbaar: in de DIC classes overschrijven
- (Vast) razendsnel
- Debug functie
De hello world app:
Vooral die uitbreiding van de views vind ik wel mooi, al zeg ik het zelf...
/hello geeft:
/hello/Rudolf
geeft
Small but Beautiful op Github met 'Hello World' applicatie.
Mochten er positieve reacties zijn, zal ik het in de scriptlib stoppen. (Om het goede voorbeeld te geven ;-) ). Alle negatieve (opbouwende) reacties zijn natuurlijk ook welkom.
Wat functionaliteiten:
- Dependency injection container
- Uitbreidbare views (layouts dus)
- View partials
- Routing. De route van het voorbeeld is: '/hello[/:name]'
- Fijn configureren in native PHP ;-)
- Alles in 1 bestand :D
- Wel mogelijkheid tot view-helpers, maar geen view-helpers
- (Soort van) OOP
- Geen ingewikkelde namespaces (wel een autoloader daarvoor)
- Goed aanpasbaar: in de DIC classes overschrijven
- (Vast) razendsnel
- Debug functie
De hello world app:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#app/routes.php
<?php
return array(
'/hello[/:name]' => array(
'defaults' => array(
'_controller' => 'hello:name',
'name' => 'Pim'
),
'requirements' => array(
'name' => '[A-z]+'
),
)
);
?>
#App/Controlers/HelloController.php
<?php
class Controllers_HelloController extends Controller {
public function nameAction($name)
{
return $this->_render('hello', array('name'=>$name));
}
}
?>
#App/views/hello.phtml
<?php
$this->extend('layout', array('title'=>'Hi '.$name));
?>
Hello <?php echo $this->e($name); ?>
#App/views/layout.phtml
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Site - <?php echo $title ?></title>
</head>
<body>
<?php
echo $content;
?>
</body>
</html>
<?php
return array(
'/hello[/:name]' => array(
'defaults' => array(
'_controller' => 'hello:name',
'name' => 'Pim'
),
'requirements' => array(
'name' => '[A-z]+'
),
)
);
?>
#App/Controlers/HelloController.php
<?php
class Controllers_HelloController extends Controller {
public function nameAction($name)
{
return $this->_render('hello', array('name'=>$name));
}
}
?>
#App/views/hello.phtml
<?php
$this->extend('layout', array('title'=>'Hi '.$name));
?>
Hello <?php echo $this->e($name); ?>
#App/views/layout.phtml
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Site - <?php echo $title ?></title>
</head>
<body>
<?php
echo $content;
?>
</body>
</html>
Vooral die uitbreiding van de views vind ik wel mooi, al zeg ik het zelf...
/hello geeft:
Code (php)
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Site - Hi Pim</title>
</head>
<body>
Hello Pim </body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Site - Hi Pim</title>
</head>
<body>
Hello Pim </body>
</html>
/hello/Rudolf
geeft
Code (php)
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Site - Hi Rudolf</title>
</head>
<body>
Hello Rudolf </body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Site - Hi Rudolf</title>
</head>
<body>
Hello Rudolf </body>
</html>
Gewijzigd op 02/01/2011 20:22:10 door Pim -
Gesponsorde koppelingen:
Er zijn nog geen reacties op dit bericht.



