https://github.com/dantleech/mvc
Really lightweight MVC framework
https://github.com/dantleech/mvc
Last synced: over 1 year ago
JSON representation
Really lightweight MVC framework
- Host: GitHub
- URL: https://github.com/dantleech/mvc
- Owner: dantleech
- Created: 2011-10-30T15:31:15.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2011-10-30T19:37:02.000Z (over 14 years ago)
- Last Synced: 2025-01-30T15:44:33.906Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 93.8 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Lightweight MVC Framework
=========================
This is a very lightweight MVC framework featuring:
- Dependency Injection
- URL Router
- Request Dispatcher
The components are inspired by Symfony2 (https://github.com/symfony).
No view or model layers are included. This is just a framework to facilitate the usage
of third party components.
You will need to setup an autoloader. I used the Symfony one - https://github.com/symfony/ClassLoader.
This is a personal project and has NO TESTS.
Example usage
-------------
An example `index.php` with including service configuration::
// web/index.php
set('router', new Service('DTL\MVC\Router\Router', array(
array(
// add routes
new Route('&/foobar/(.*)/(.*)&', array('pronoun', 'subject'), 'DTL\FixturatorWeb\Controller\HomeController::index'),
)
)));
// set monolog for logging (https://github.com/Seldaek/monolog)
$sc->set('logger', Service::create('Monolog\Logger', array('MVC'))
->addMethodCall('pushHandler', array(new Service('Monolog\Handler\StreamHandler', array(
__DIR__.'/../log/web.log',
))))
)
;
// set the TWIG template engine for use in the controllers (https://github.com/fabpot/twig)
$sc->set('twig', new Service('\Twig_Environment', array(
new Service('\Twig_Loader_Filesystem', array(
__DIR__.'/../lib/DTL/FixturatorWeb/views',
))
)));
$dispatcher = new Dispatcher($sc);
$request = Request::createFromGlobals();
$dispatcher->dispatch($request);
And an example controller::
setBody($sc->get('twig')->render('Home/index.html.twig', array('hello' => 'world')))
->setStatusCode(200)
->setHeader('Content-Type', 'text/html');
}
}