Check documentation for the latest version of dhtmlxSuite Step 3. Create a Model DHTMLX Docs

Step 3. Create a Model

To access the data we need to specify the appropriate model class.

To know more about using models, read the Models article from the YII framework documentation.

To create models:
  1. Create 3 files with the names "GanttTask.php", "GanttLink.php","SchedulerEvent.php" in the "yii_dhtmlx/models" directory.
  2. Open the "GanttTask.php" file and add the following code there:

    "GanttTask.php" file

    <?php
    namespace app\models;
    use yii;
    use yii\db\ActiveRecord;
     
    class GanttTask extends ActiveRecord {
        public static function tableName(){
            return "gantt_tasks";
        }
        public static function primaryKey(){
            return array("id");
        }
    }


  3. Add the code below into the "GanttLink.php" file:

    "GanttLink.php" file

    <?php
    namespace app\models;
    use yii;
    use yii\db\ActiveRecord;
     
    class GanttLink extends ActiveRecord {
        public static function tableName(){
            return "gantt_links";
        }
        public static function primaryKey(){
            return array("id");
        }
    }


  4. Put the following code to the "SchedulerEvent.php" file:

    "SchedulerEvent.php" file

    <?php
    namespace app\models;
    use yii;
    use yii\db\ActiveRecord;
     
    class SchedulerEvent extends ActiveRecord {
        public static function tableName(){
            return "scheduler_events";
        }
        public static function primaryKey(){
            return array("event_id");
        }
    }


  5. For Grid we'll use the same model as the one used for Scheduler - 'scheduler_events'.
Back to top