Welcome Guest, Not a member yet? Register   Sign In
Ignite Drupal
#1

[eluser]Unknown[/eluser]
Drupal Module: ignite_drupal

More info here:
http://drupal.org/node/1247682

Quote:WARNING: You must have a bit of CodeIgniter and MVC/OOP knowledge to be able to read the following

Ever since I was literally forced to work with drupal, I have always wondered about the following:
1) What if I would be able to call CI controllers directly from my drupal functions/hooks, etc.
2) What if I would be able to load anything I want into drupal and everything that's in the CI autoload automatically ?
3) What if I would not change anything to the CI core so that CI may be uupdated at all times ?
4) What if I would be able to call any Drupal API function inside my CI controllers ? Any Drupal function.
5) What if I would be able to manage URI routing using both CI and Drupal.
6) What if I would be able to setup a Drupal hook_menu() item, and that menu item's path would automagically call one of my CI controllers/method ?

Now all that, and more in this simple drupal module (see attachment)

How to use it ?
Step 1: Installing the drupal module.
- Unzip the ignite_drupal archive and copy the ignite_drupal folder in it to your drupal installation under sites/all/modules
- Go to your drupal admin area, click on modules and scroll down until you see the Ignite Drupal module
- Check the box beside that module
- Scroll down more and click the Save button.

Step 2: Installing the CodeIgniter MVC
- Download the latest version of CodeIgniter from the CI website
- Unzip and copy the CodeIgniter you just downloaded to a folder of your preference inside your drupal installation. HINT: The ignite_drupal module will automatically look for the mvc folder. So should be: /path/to/drupal/mvc However you can put it in any folder you like. You'll just have to specify the folder name when you instantiate the CI front controller though.
It is IMPERATIVE however to place it inside your drupal installation and not anywhere else. No deeper in the installation or outside of it.
- Now copy the contents of the folder: ci_core_patches in your mvc installation folder. It should write 3 patches to your application/core folder contents.
To the CI-savy people: This just extends 3 Core components to make them act-rite :-)

Step 3: Actually use it :-)
I'll just post some sample code from both drupal and one of my CodeIgniter controllers to see how it works:

CODEIGNITER PART
In one of my CI controllers I have the following code:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class App extends CI_Controller {
        
    public function __construct(){
        parent::__construct();
    }


    public function index($uid = 69){
        // Let's not forget drupal API's user_load function.
        $user_info = user_load($uid);
        print_r($user_info);
        
        /* Load and render some views if we wish
         * $this->data in my case is an array containing data to put in the views.
    $this->load->view('common/header', $this->data);
        $this->load->view('app', $this->data);
        $this->load->view('common/footer', $this->data);
        */
    }
    
}

/* End of file app.php */
/* Location: ./application/controllers/app.php */




DRUPAL PART
In one of my custom drupal modules I have the following code:

Code:
<?php
// "Implementation" of drupal's hook_menu.
function module_hook_menu() {

    $items = array();
    
    $items['class/method'] = array(
        'title' => t(""),
        'page arguments' => '',
        'access callback' => TRUE,
        'page callback' => 'call_class_and_method',
        'type' => MENU_CALLBACK
    );
    
    $items['codeigniter'] = array(
        'title' => t(""),
        'page arguments' => '',
        'access callback' => TRUE,
        'page callback' => 'codeigniter',
        'type' => MENU_CALLBACK
    );

    $items['blank'] = array(
        'title' => t(""),
        'page arguments' => '',
        'access callback' => TRUE,
        'page callback' => 'blank',
        'type' => MENU_CALLBACK
    );
    return $items;
}

function call_class_and_method(){
    // Start CodeIgniter
    $dci = new ignite_drupal();
    
    // This attempts to load the CI controller "class" and method "method"
    $CI = $dci->load_controller();
}
function codeigniter(){
    // Make Drupal logic here
    //........


    // Start CodeIgniter
    $dci = new ignite_drupal();
    
    // This loads the specified controller and method.
    $CI = $dci->load_controller("my_controller", "that_controllers_method");
}
function blank(){
    // Start CodeIgniter
    $dci = new ignite_drupal();

    /*
     * Assuming you have created a controller called blank with a method called index
     * you may now use all CI functions right here to achieve your ultimate logic goals
     * this way you get help from both Drupal and CI. Play with this anyway you want.
     */
    $CI = $dci->load_controller("blank", "index");
    
    // ignite_drupal module will automatically load all libraries and all the stuff inside autoload.php    

    // However we may also load our custom or core libraries manually.
    //$CI->load->library("my_library");
    
    // Use the CI libraries and everything else we want.
    
    // User it for sessions
    $CI->session->set_userdata("uid", "69");
    $user_id = $CI->session->userdata("uid");
    echo "<h1>The user id from the cookie session is: " . $user_id . "</h1>";
    
    // Use it for models ! :D
    $CI->load->model("model_name");
    $my_stuff = $CI->model_name->get_stuff_by_name($stuff_name);

    // Use it for anything else you want ! It accepts all CI's components.
    // ..............

}




Theme © iAndrew 2016 - Forum software by © MyBB