Skip to content

Instantly share code, notes, and snippets.

@mekanics
Forked from docteurklein/silex_app.php
Created January 9, 2012 20:26
Show Gist options
  • Select an option

  • Save mekanics/1584765 to your computer and use it in GitHub Desktop.

Select an option

Save mekanics/1584765 to your computer and use it in GitHub Desktop.

Revisions

  1. @docteurklein docteurklein created this gist Apr 8, 2011.
    40 changes: 40 additions & 0 deletions silex_app.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    <?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();