How To Integrate Yii Framework And Propel

I have been done a project that require use Propel and Yii Framework to connect my application and database. Why i use Propel in Yii Framework and why not active record ? I dont like say it, but it requirement from the project. So before that, i will say about use Propel in Yii Framework :

1. Yii have active record for database, if you use Propel or any ORM you will lost Yii active record. And if you think you can use both of it, i think bad idea.

2. Some extension in Yii use Yii class that use active record. If you use Propel or another ORM, you must modify your extension. For example i use “rights” extension for user management and must modify it.

3. I dont say active record better that propel or propel better thatn active record, but for me in Yii Framework, active record is the best way to manage your database.

4. You must learn again about how to use Propel.. 🙂

So this is way to integrate propel and Yii Framework :

1. create your propel

2. insert it in your project, for example insert it in directory “yourapplication/protected/vendor/propel”

3. Edit your root index.php from :

 <?php
$yii=dirname(__FILE__).'/../yii/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
require_once($yii);
Yii::createWebApplication($config)->run();

to :

 <?php
$yii=dirname(__FILE__).'/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
require_once($yii);

spl_autoload_unregister(array('YiiBase','autoload'));
require_once ('protected/vendor/propel/runtime/lib/Propel.php'); // this is your propel path

Propel::init("protected/vendor/propel/build/conf/crm-conf.php"); // this is your propel database class path
set_include_path("protected/vendor/propel/build/classes" . PATH_SEPARATOR . get_include_path());

spl_autoload_register(array('Propel', 'autoload'));
spl_autoload_register(array('YiiBase', 'autoload'));

Yii::createWebApplication($config)->run();

After that you can use propel for your application,..

Finish.. hope it help..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: