-
Notifications
You must be signed in to change notification settings - Fork 0
Using Propel as Model
Category:Libraries Category:Libraries::Database Category:Libraries::Model
This document has not been updated sometime so I will try to complete it from the experience I had with Propel. I have been using Propel 1.3 with CI and it has been working great!!
First, install Propel to your system. I recommend using Propel 1.3 as it uses PDO instead of Creole for DB abstraction and the performance gain is as much as 100% over PDO against Creole.
URL to the Propel-Framework: [url]http://propel.phpdb.org/trac/[/url]
Please follow the steps below to setup Propel in your system:
[b]1. Installation of Propel 1.3[/b] [url]http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3/Installation[/url] [b]2. Propel Quick Start Guide[/b] [url]http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3/QuickStart[/url]
Now you have Propel in your system and let's try to integrate it with CI
[b]1. Setup include_path for Propel core and class files[/b] The directory where propel class files are generated needs to be included in include_path environment variable. Also directory for Propel core files can be included if you want to use relative path in the Propel library file for CI.
I have set the include_path in my apache config file so the setting looks like this: [code] php_value include_path ".:/home/me/htdocs:/home/me/propel_classes:/usr/share/php" [/code]
This means that propel class files are found in "/home/me/propel_classes" and Propel include file "propel/Propel.php" is found under "/usr/share/php".
Of course you can also set include_path at runtime or in .htaccess.
[b]2. Create Propel library in CI[/b] In your system/application/library directory of CI, create a file called Propel.php with the following content. [code] <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once('propel/Propel.php'); Propel::init("conf/yourdb-conf.php");
?> [/code]
yourdb-conf.php should be altered to whichever database name you have decided to use.
[b]3. Include in autoload (optional)[/b] If you don't want to include the Propel library for every Controller you will be creating you can include that in system/application/config/autoload.php
[code] $autoload['libraries'] = array('propel'); [/code]
[b]4. include Propel files in controller[/b] You are ready to use Propel now so let's try to include it in your controller.
For example, Home Controller in system/application/controller/home.php that loads Propel class "Message.php" in looks like this:
[code] <?php
class Home extends Controller {
function __construct() { parent::Controller();
require_once('Message.php');
}
function index() { //do whatever you need to do here } }
?>
Pretty simple, no? Enjoy!!