This is a working skeleton used to rapidly develop a new Silex site, with Twitter Bootstrap, Twig, and a Doctrine ORM provider installed and registered. It also includes the Doctrine console and a CRUD generator in the /bin directory, which uses components from Zend Framework 2.x.
###Included Packages
- Twig 1.12 (twig/twig)
- Doctrine ORM Provider (taluu/doctrine-orm-provider)
- Twitter Bootstrap installed is in 'web' directory. The requisite CSS and JS includes are in the views/base.twig.html template. Extend the base template in other Twig files if you want to use Bootstrap.
- Zend/Form
###Installation using Composer
- From the web root:
composer create-project --stability="dev" smith981/silex-skeleton silex
- Or, if you haven't renamed composer.phar:
php composer.phar create-project --stability="dev" smith981/silex-skeleton silex
This will create the installation in the 'silex' directory. 2. Change the title in src/smith981/silex-skeleton/views/base.twig.html so that it shows your site name. 3. If you need a database, open index.php and uncomment the lines that register Doctrine DBAL and edit the connection parameters there. 4. Create your routes as needed in index.php, and your views in the src/smith981/silex-skeleton/views.
Package includes .htaccess used for removing 'index.php' from url! Be sure .htaccess overrides are allowed by your httpd.conf settings.
I have not attempted to run this under IIS, pull requests are welcome on this.
For examples, see comments in index.php.
Uncomment the following code in /index.php and set your database parameters:
<?php
// /index.php
// ...
/**
* Register Doctrine DBAL if needed
*/
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
// Doctrine DBAL settings goes here
'db.options' => array(
'driver' => 'pdo_mysql',
'user' => 'username',
'password' => 'pass',
'dbname' => 'dbname',
'host' => 'localhost'
)
));
The doctrine console is located in '/bin'
cd bin
./doctrine
Just plug your connection parameters into /bin/boostrap_doctrine.php. Everything else is done!
<?php
// /bin/bootstrap_doctrine.php
// ...
/**
* database configuration parameters for Doctrine console
*/
$conn = array(
'driver' => 'pdo_mysql',
'dbname' => 'test',
'user' => 'testuser',
'password' => 'secret',
'host' => 'localhost',
);
While you are welcome to simply use the Doctrine DBAL, the Doctrine ORM is available as well.
By default, this package supports mapping info via annotations. See Doctrine 2 documentation.
Your entity models go in /entities. Any .php file in that directory will be included automatically. The three sample entities from the Doctrine 2 documentation are included.
To remove the sample entities, delete those files and recreate the schema:
cd bin
./doctrine orm:schema-tool:drop --force
./doctrine orm:schema-tool:create
Add your own entity files in /src/smith981/silex-skeleton/entities and create or update the schema:
./doctrine orm:schema-tool:update