/propignite

A library that allows to use Propel 2 with Codeigniter 3.1.5

Primary LanguagePHPMIT LicenseMIT

Propignite

A Propel 2 library that works with Codeigniter

Use Propel 2 active record with Codeigniter. Replace the default Codeigniter active record with the powerful one given by Propel 2.

Easy to install

Clone or download the repository from this page or run:

git clone -u master https://github.com/alessandrofrenna/propignite.git <output_directory>

Run the command in a command line interface such bash, cmd..

Now that you cloned the library, copy the cloned files to your project folder and, add to your composer.json:

"require" : {
    //other libraries...
    "propel/propel" : "~2.0@dev"
}, 

...

"autoload" : {
    "psr-4": {
        "Codeigniter\\Propel": "application/libraries/Propel"
    }
} 
composer update

If you don't have a composer.json file, feel free to copy in your project folder our composer.json file and then run:

composer install

Make it works:

  • Open your autoload configuration file in your application/config folder.

  • Search for $autoload['libraries'] and add 'Propel/Propel' => 'propel' to the array.

        $autoload['libraries'] = ('...others', 'Propel/Propel' => 'propel');
  • Save the configuration file and exit.

What about configuration ?

You can edit application/config/propel.php file to meet your requirements.

The propel.php file, contains the basic configuration parameters that must be used to make Propel 2 works properly.

The file include configurations for:

  • Database:

    1. Connections. Connections are defined in the following way

      $active_record['propel']['database']['connections']['<database name>'] = [
          //PARAMS...
      ]
  • Paths: here we define the default path used to store almost all of the Propel 2 generated files.

It is risky to edit this part of the configuration file. If you don't want to have troubles don't touch this part of the config file.

  • Runtime:

    1. Each time you need, use defaultConnection to set the default database connection to use.
    2. Add in the connections array, all the connections defined in the Database > Connection configuration.
  • Generator:

    1. Each time you need, use defaultConnection to set the default database connection to use with the generator.
    2. Add in the connections array, all the connections defined in the Database > Connection configuration.
  • Reverse

Don't touch this configuration part to avoid trouble at runtime

  • Migrations

Don't touch this configuration part to avoid trouble at runtime

Obviously, these are the basic configurations provided by this library.

You can add other parameters by following the documentation: Configuration Reference.

Ready, Set... Go!

It's time to make everything work. Propel 2 comes with an integrated CLI that can be found inside vendor/bin/propel. Use the command vendor/bin/propel list to see the list of all the commands.

Each file that is generated by the CLI is stored inside your project's root folder inside the propel directory.

IMPORTANT: each command you run, must be followed by --config-dir application/config to avoid errors.

Generate a usable configuration file for the library:

vendor/bin/propel config:convert --config-dir application/config

This command is IMPORTANT because it helps us to generate the correct configuration file for the library. Run the command each time you update your application/config/propel.php file.

Know your schema:

You should know that Propel 2 schema is an XML file that contain all the code to generate our table queries. You can find schema inside root/propel/schema directory.

Build SQL:

When you create the schema file, you shall build the relative SQL Queries. The built queries will be inside root/propel/sql directory. Run:

vendor/bin/propel sql:build --config-dir application/config

To run the queries use:

vendor/bin/propel sql:insert --config-dir application/config

Generating models:

Models for you database tables will be generated inside the root/application/model directory. Each model generated by Propel 2, must have the Codeigniter\Models namspace, that can be defined as parameter inside the schema file like this:

<database name="<you db name>" defaultIdMethod="native" namespace="Codeigniter\Models">

To actually generate models from schema, use this command:

vendor/bin/propel model:build --config-dir application/config

Following:

Read the full documentation to learn about Propel 2 and how to use it.