# PHP/Doctrine bootstrap for review

Here's my bootstrap.php for my PHP/MySQL/Doctrine app. It's my first PHP app so I'm interested in learning from the experience of others how this could be improved - security-wise, performance-wise, or otherwise.

//-------------------------------------------------------------------------
// Define global constants
define('ROOT_PATH', dirname(__FILE__) . '/');
define('URL_BASE', 'http://localhost/myapp/public/');
define('LIB_PATH', 'C:\\wamp\\www\\lib\\');
define('OPENID_PATH', 'C:\\wamp\www\\lib\\lightopenid.git\\openid.php');

//-------------------------------------------------------------------------
// Bootstrap Doctrine.php, register autoloader, specify
// configuration attributes and load models.
require_once(LIB_PATH . 'doctrine12/lib/Doctrine.php');
$manager = Doctrine_Manager::getInstance(); //------------------------------------------------------------------------- // Define database connection$dsn = 'mysql:dbname=mydb;host=127.0.0.1';
$user = 'xxx';$password = 'yyy';
$dbh = new PDO($dsn, $user,$password);
$conn = Doctrine_Manager::connection($dbh);

//-------------------------------------------------------------------------
// Set defaults
$manager->setAttribute(Doctrine::ATTR_DEFAULT_COLUMN_OPTIONS, array('type' => 'string', 'length' => 255, 'notnull' => true));$conn->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true);
$manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true); // Don't load a model until it's needed (causes problems when this is on) //$manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE);

//-------------------------------------------------------------------------
// Import model objects

• How different is this from the default template? Can you link to it? Jan 20 '11 at 1:30
• – BenV
Jan 20 '11 at 3:30
• @ZoranJankov I have rejected your suggested edit because it does not improve the quality of the title. A title must uniquely describe what the script does -- not what it is & what it is comprised of. Nov 13 '20 at 23:26

Here are a few lines that might be useful to add if you would like to use these options:

/**
* Needed for SoftDelete to work
*/
$manager->setAttribute(Doctrine::ATTR_USE_DQL_CALLBACKS, true); /** * Tell doctrine to look for custom ___Table classes in the models folder */$manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);


where you state Define global constants your not defining your directories with the correct slashes for the Operating system

You can use / slashes fluently on your application as both unix and windows supports them but if you really want to be on the safe side then you should use DIRECTORY_SEPARATOR

As Doctrine 2.0 is only supporting PHP 5.3.0 you can replace dirname(__FILE__) with __DIR__

I would also create a constant called DS which would normally be created in a constants file, and should be one of the first included.

I would convert the above to:

 define('ROOT_PATH'  ,  __DIR__);
define('URL_BASE'   ,  'http://localhost/myapp/public/');
define('LIB_PATH'   ,  realpath("../../path/to/libs")); //Unix / Windows
define('OPENID_PATH',  realpath("../../path/to/openid"));//Unix / Windows


And then change the loadModels accordingly?

• Excellent information, thanks! Just one point of clarification - you never stated what the DS constant is or where you would use it.
– BenV
Jan 29 '11 at 15:10
• sorry, the DS Constants is a shortor version for DIRECTORY_SEPARATOR and you would then build your paths like so: LIB_ROOT . DS . "openid" . DS . "openid.class.php" to save line space. Jan 29 '11 at 15:50