The Entry Script
From the diagram in the previous page, we know that index.php is the PHP script that handles user requests initially.
In a basic application, the index.php will contain minimal code as below:
include './protected/config/common.conf.php'; include './protected/config/routes.conf.php'; include $config['BASE_PATH'].'Doo.php'; include $config['BASE_PATH'].'app/DooConfig.php'; Doo::conf()->set($config); Doo::app()->route = $route; Doo::app()->run();
Basically, the index.php loads in common project settings and routes you have defined. Then, an instance of a web application is created with the configurations.
If you are using database ORM tool, you would have code as below:
include './protected/config/common.conf.php'; include './protected/config/routes.conf.php'; include './protected/config/db.conf.php'; include $config['BASE_PATH'].'Doo.php'; include $config['BASE_PATH'].'app/DooConfig.php'; # database usage Doo::db()->setMap($dbmap); Doo::db()->setDb($dbconfig, $config['APP_MODE']); Doo::db()->sql_tracking = true; Doo::conf()->set($config); Doo::app()->route = $route; Doo::app()->run();
The DB setMap() method is used for setting up tables relationship in the database. sql_tracking is used for logging down SQL queries executed in your app. You can retrieve the list of executed queries by writing the following code:
print_r( Doo::db()->show_sql() );
In production mode, you might want to use DooPHP's deploy script which combines several core classes of the framework in one file. It is optimized for performance.
include './protected/config/common.conf.php'; include './protected/config/routes.conf.php'; include './protected/config/db.conf.php'; include $config['BASE_PATH'].'deployment/deploy.php'; Doo::conf()->set($config); Doo::db()->setMap($dbmap); Doo::db()->setDb($dbconfig, $config['APP_MODE']); Doo::app()->route = $route; Doo::app()->run();
To have clean URls without 'index.php' you must enable mod_rewrite in Apache and in the .htaccess you would have:
RewriteEngine On
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule .* index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
There's a .htaccess.example in the app folder. Just rename it to .htaccess
