Check documentation for the latest version of dhtmlxSuite Using Connector with Popular Frameworks DHTMLX Docs

Using Connector with Popular Frameworks

Since version 2.2, dhtmlxConnector has been updated to work with latest versions of frameworks (CodeIgniter, Yii and CakePHP) and started supporting integration with the Laravel framework. You can built web applications with your favorite frameworks and still use dhtmlxConnector.

In case you need information on integration of dhtmlxConnector with the earlier versions of frameworks, you can read the chapter Using Connector with Frameworks (version 1.5).

In this article you will find useful tips on the usage of dhtmlxConnector in your apps created with one of the listed frameworks. The detailed information is given in the related tutorials:

  1. Using dhtmlxConnector with the CodeIgniter framework;
  2. Using dhtmlxConnector with the Yii framework;
  3. Using dhtmlxConnector with the CakePHP framework;
  4. Using dhtmlxConnector with the Laravel framework.

For example, let's consider creating an app that presents a grid loaded with data from db. The app is built with one of the frameworks and uses dhtmlxConnector to load data in.

Tips common for all frameworks

Model:

Doesn't have any specificity and created as usual.

View:

  • View contains a standard JavaScript code of the component and defines the client side logic;
  • To load data use standard 'loading' methods of the components but as the URL parameter specify the relative path to an action that answers for loading logic. If you use dataProcessor, specify in its constructor this relative path to the action as well;
mygrid = new dhtmlXGridObject('grid_here'); 
...
mygrid.init();                           
mygrid.load("./data"); //refers to the 'data' action 
 
var dp = new dataProcessor("./data"); //refers to the 'data' action as well
dp.init(mygrid);

Common tips on configuring controller for Yii, CakePHP and Laravel

  • Controller defines the server side logic and contains at least 2 actions: one loads the view, the other one loads the data;
  • SQL query to database is configured with the help of the configure() method that takes as parameters:
    • new $modelName - the method creating a model for working with a database
      (for CakePHP use TableRegistry::get($modelName) - this method will return a model);
    • $id - the name of the id field;
    • $text - a comma-separated list of rendered data fields;
    • $extra - (optional) a comma-separated list of extra fields;
    • relation_id - (optional) used for building hierarchy in case of Tree and TreeGrid.
  • GridConnector (or any other connector) takes as parameters:
    • null to specify that a model is used for working with a database;
    • the hardcoded value specifying the framework ( "PHPYii", "PHPCake" or "PHPLaravel").
//sample code for the Laravel framework
<?php
namespace App\Http\Controllers;
use App\SchedulerEvent;
use Dhtmlx\Connector\GridConnector;
 
class GridController extends Controller
{
    public function data() {                                    
        $connector = new GridConnector(null, "PHPLaravel"); 
        // the SchedulerEvent() method is used to create the model
        $connector->configure(                                  
            new SchedulerEvent(),                               
            "event_id",                                         
            "start_date, end_date, event_name"                  
        );                                                      
        $connector->render();                                   
    }                                                           
}

Specific tips on configuring controller for CodeIgniter

  • To handle an event, add a function of the corresponding event name (e.g. to handle the beforeRender event, add public function beforeRender($action){...}) and define the handling logic as usual. The functions will take the same parameters as the ordinary events do;
  • SQL query to database is configured with the help of the configure() method that takes as parameters:
    • $table - the name of the table;
    • $id - the name of the id field;
    • $text - a comma-separated list of rendered data fields;
    • $extra - (optional) a comma-separated list of extra fields;
    • relation_id - (optional) used for building hierarchy in case of Tree and TreeGrid.
  • GridConnector (or any other connector) takes as parameters:
    • the DB connection variable that refers to the model used in the app;
    • the hardcoded value specifying the framework ( "PHPCI").
//sample code for the CodeIgniter framework
<?php  
use Dhtmlx\Connector\GridConnector;
 
class Grid extends CI_Controller {                  
    public function index(){       
        $this->load->view("GridView");  
    }
    public function data(){                                 
        $this->load->database(); // data feed               
 
        $connector = new GridConnector($this->db, "PHPCI"); 
        $connector->configure(                              
            "scheduler_events",                             
            "event_id",                                     
            "start_date, end_date, event_name"              
        );                                                  
        $connector->render();                               
    }                                                       
};
Back to top