Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Persistence in PHP with Doctrine ORM

You're reading from  Persistence in PHP with Doctrine ORM

Product type Book
Published in Dec 2013
Publisher Packt
ISBN-13 9781782164104
Pages 114 pages
Edition 1st Edition
Languages
Author (1):
Kevin Dunglas Kevin Dunglas
Author Profile Icon Kevin Dunglas
Kevin Dunglas
Toc

Bootstrapping the app


The following steps need to be performed for bootstrapping the app:

  1. 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 called blog.db stored in the data/ 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 is true, some optimizations will be disabled to ease debugging. Disabling the dev 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.

  2. Next, we need a way to bootstrap our app. Create a file called bootstrap.php in the src/ 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.

You have been reading a chapter from
Persistence in PHP with Doctrine ORM
Published in: Dec 2013 Publisher: Packt ISBN-13: 9781782164104
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime