Check documentation for the latest version of dhtmlxSuite Step 4. Create a Controller DHTMLX Docs

Step 4. Create a Controller

In the controller, we need to implement 3 actions:

  1. One, that loads grid's and scheduler's views
  2. One, that loads data to the grid
  3. One, that loads data to the scheduler

To load and process data we will use GridConnector. A common use of GridConnector is:

$connector = new GridConnector($db, $type);
$connector->configure($table,$id, $text, $extra,$relation_id);
$connector->render();

The GridConnector constructor takes 2 parameters:

  • $db - the DB connection variable;
  • $type - the database type.

Remember, in case of working with CakePHP, the parameters will get the values:
$this→Event (refers to the model used in the app) and "PHPCake" (the hardcoded value).


The configure method configures the GridConnector object without rendering data and takes 5 parameters:

  • $table - the name of a 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.
To configure the Controller object:
  1. Create a new file in the "controllers " folder and name it "EventController.php ".
  2. Open the "EventController.php " file and add files required for working with dhtmlxConnector:

    "controllers/EventController.php" file

    <?php 
        require_once("../Vendor/connector/grid_connector.php");
        require_once("../Vendor/connector/scheduler_connector.php");
        require_once("../Vendor/connector/db_phpcake.php");
  3. Create the root controller class "EventController " with the primary "Index " action and actions answering for displaying the components:

    "controllers/EventController.php" file

    <?php 
    require_once("../Vendor/connector/grid_connector.php");
    require_once("../Vendor/connector/scheduler_connector.php");
    require_once("../Vendor/connector/db_phpcake.php");
     
        class EventController extends AppController {         public function grid(){}                          public function scheduler(){}                     public function index(){}                     }
  4. Create an action that will load data to the grid:

    "controllers/EventController.php" file

    <?php 
    require_once("../Vendor/connector/grid_connector.php");
    require_once("../Vendor/connector/scheduler_connector.php");
    require_once("../Vendor/connector/db_phpcake.php");
     
        class EventController extends AppController { 
            public function grid(){}                  
            public function scheduler(){}            
            public function index(){}                
        }
        public function grid_data(){                                                            $this->autoRender = false;                                                          $connector = new GridConnector($this->Event, "PHPCake");                            $connector->configure("events","event_id","start_date,end_date,event_name");        $connector->render();                                                           }
  5. Create an action that will load data to the scheduler:

    "controllers/EventController.php" file

    <?php 
    require_once("../Vendor/connector/grid_connector.php");
    require_once("../Vendor/connector/scheduler_connector.php");
    require_once("../Vendor/connector/db_phpcake.php");
     
        class EventController extends AppController { 
            public function grid(){}                  
            public function scheduler(){}             
            public function index(){}                 
        }
        public function grid_data(){                                                    
            $this->autoRender = false;                                                  
            $connector = new GridConnector($this->Event, "PHPCake");                    
            $connector->configure("events","event_id","start_date,end_date,event_name");
            $connector->render();                                                      
        } 
        public function scheduler_data(){                                                       $this->autoRender = false;                                                           $connector = new SchedulerConnector($this->Event, "PHPCake");                       $connector->configure("events","event_id","start_date,end_date,event_name");        $connector->render();                                                           }
Back to top