-
-
Save mekanics/1584765 to your computer and use it in GitHub Desktop.
a little silex app to show doctrineExtension capabilities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__.'/../Silex/silex.phar'; | |
use Silex\Extension\DoctrineExtension; | |
$app = new Silex\Application; | |
$app->register(new DoctrineExtension, array( | |
'doctrine.dbal.connection_options' => array( | |
'driver' => 'pdo_mysql', | |
'dbname' => 'test', | |
'host' => 'localhost', | |
'user' => 'root', | |
'password' => null | |
), | |
'doctrine.orm' => true, | |
'doctrine.orm.entities' => array( | |
array('type' => 'annotation', 'path' => __DIR__.'/Entity', 'namespace' => 'Entity'), | |
), | |
'doctrine.common.class_path' => __DIR__.'/vendor/doctrine_common/lib', | |
'doctrine.dbal.class_path' => __DIR__.'/vendor/doctrine_dbal/lib', | |
'doctrine.orm.class_path' => __DIR__.'/vendor/doctrine_orm/lib', | |
)); | |
$app['autoloader']->registerNamespace('Entity', __DIR__); | |
$app->get('/', function() use($app) { | |
$conn = $app['doctrine.dbal.connection']; | |
$categories = print_r($conn->query('SELECT * FROM category')->fetchAll(), true); | |
return 'Hello <pre>'.$categories.'</pre>'; | |
}); | |
$app->get('/category/{slug}', function($slug) use($app) { | |
$em = $app['doctrine.orm.em']; | |
$entity = $em->getRepository('Entity\Category')->findOneBy(array('slug' => $slug)); | |
return 'Hello '.$entity; | |
}); | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment