Full Stack Software Developer

Configuring propel ORM for CodeIgniter 3.1

Turn composer autoloader on in CodeIgniter config file at application/config/config.php. Then install propel through composer by typing in the following code in the terminal. Make sure you are at the root of your CodeIgniter application where composer.json file is.

composer require propel/propel

Once propel is installed we need to connect our database to propel. For this we need to create a config file. To create the config file for propel use their interactive config generator. Once all inputs are taken propel generates the config file at /generated-config/config.php. Some other files are also created apart from the config file. But one this which is ideal to do is to provide a folder name for generated classes. For example I gave /orm as my generated class path so that all files are stored within one single folder rather than being created at the CodeIgniter framework root.

./vendor/bin/propel init

Once the config file is generated we have to make sure it loads prior to the controller files being processed. Thats why we need to turn on hooks in application/config/config.php then inside application/config/hook.php write the following pre_controller hook code. This will ensure the propel config file is loaded before our controller is executed.

$hook['pre_controller'] = function()
{
	require_once FCPATH.'generated-conf/config.php';
};

Disclaimer:
This code is suppose to be an outline on how to get propel install on CodeIgniter 3.1 and details are avoided to keep the post concise.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.