Bootstrapping the app
The following steps need to be performed for bootstrapping the app:
Create a new file called
config/config.php
that will contain configuration parameters of our app as shown in the following code:<?php // App configuration $dbParams = [ 'driver' => 'pdo_sqlite', 'path' => __DIR__.'/../data/blog.db' ]; // Dev mode? $dev = true;
The Doctrine configuration parameters are stored in the
$dbParams
array. We will use a SQLite Database calledblog.db
stored in thedata/
directory. If you want to use MySQL or any other DBMS, it's here that you will configure the driver to use, the database name, and the access credentials.Note
The following is a sample configuration to use MySQL instead of SQLite:
$dbParams = [ 'driver' => 'pdo_mysql', 'host' => '127.0.0.1', 'dbname' => 'blog', 'user' => 'root', 'password' => '' ];
Config keys are self-explanatory.
If the
$dev
variable istrue
, some optimizations will be disabled to ease debugging. Disabling thedev
mode allows Doctrine to put a lot of data such as metadata in powerful caches to increase overall performances of the app.Note
It requires cache driver installation and extra configuration, which is available at http://docs.doctrine-project.org/en/latest/reference/caching.html.
Next, we need a way to bootstrap our app. Create a file called
bootstrap.php
in thesrc/
directory. This file will load everything we need as given in the following code:<?php require_once __DIR__.'/../vendor/autoload.php'; require_once __DIR__.'/../config/config.php';
The first line requires the Composer autoloader. It allows you to automatically load the Doctrine's classes, the project's classes (that will be in the
src/
directory), and any class of a library installed with Composer.The second line imports the configuration file of the app. The project structure is created and the initialization process of the app is done. We are ready to start using Doctrine.