2015-05-26 4 views
3

Я делаю плагин для ILIAS, и я использую эту ошибку, когда пытаюсь вызвать для чего-либо связанную с базой данных базу данных. Я включаю файл dbupdate в файле конфигурации, чтобы иметь возможность обновлять его и изменять его при разработке плагина.Вызов функции-члена таблицыColumnExists() по нуле

(Это потому, что я считаю, что ИЛИАС использует только dbupdate при установке плагина.)

код дает ошибку на:

if(!$ilDB->tableColumnExists('rep_robj_xptg_data','id')) 
{ 
    $ilDB->addTableColumn(
     'rep_robj_xptg_data', 
     'id', 
     array(
      'type'   => 'integer', 
      'length'   => 4000 
     ) 
    ); 
} 

Колонка и «ид» существуют в база данных. Я считаю, что это необходимо, чтобы иметь возможность сохранять данные в базе данных в будущем.

Update

Это код, который 'вызовы':

<?php 

    include ("/Customizing/global/plugins/Services/Repository/RepositoryObject/Presentations2Go/sql/dbupdate.php"); 
    require_once('./Services/Component/classes/class.ilPluginConfigGUI.php'); 
    require_once('class.ilPresentations2GoPlugin.php'); 
    require_once('class.ilObjPresentations2Go.php'); 
    //require ("/Customizing/global/plugins/Services/Repository/RepositoryObject/Presentations2Go/sql/dbupdate.php"); 

    /** 
    * Presentations2Go configuration user interface class 
    * 
    * @author Bonny van den Bovenkamp 
    * @version $Id$ 
    * 
    */ 
    class ilPresentations2GoConfigGUI extends ilPluginConfigGUI 
    { 
     /** 
     * Handles all commmands, default is "configure" 
     */ 
     function performCommand($cmd) 
     { 

      switch ($cmd) 
      { 
       case "configure": 
       case "save": 
        $this->$cmd(); 
        break; 

      } 
     } 

     /** 
     * Configure screen 
     */ 
     function configure() 
     { 
      global $tpl; 

      $form = $this->initConfigurationForm(); 
      $tpl->setContent($form->getHTML()); 
     } 

     // 
     // From here on, this is just an Presentations2Go implementation using 
     // a standard form (without saving anything) 
     // 

     /** 
     * Init configuration form. 
     * 
     * @return object form object 
     */ 
     public function initConfigurationForm() 
     { 
      global $lng, $ilCtrl; 

      $pl = $this->getPluginObject(); 

      include_once("Services/Form/classes/class.ilPropertyFormGUI.php"); 
      $form = new ilPropertyFormGUI(); 

      // setting 1 (a checkbox) 
      $cb = new ilCheckboxInputGUI($pl->txt("setting_1"), "setting_1"); 
      $form->addItem($cb); 

      // setting 2 (text) 
      $ti = new ilTextInputGUI($pl->txt("setting_2"), "setting_2"); 
      $ti->setRequired(true); 
      $ti->setMaxLength(10); 
      $ti->setSize(10); 
      $form->addItem($ti); 

      $form->addCommandButton("save", $lng->txt("save")); 

      $form->setTitle($pl->txt("Presentations2Go configuration")); 
      $form->setFormAction($ilCtrl->getFormAction($this)); 

      return $form; 
     } 

     /** 
     * Save form input (currently does not save anything to db) 
     * 
     */ 
     public function save() 
     { 
      global $tpl, $lng, $ilCtrl; 

      $pl = $this->getPluginObject(); 

      $form = $this->initConfigurationForm(); 
      if ($form->checkInput()) 
      { 
       $set1 = $form->getInput("setting_1"); 
       $set2 = $form->getInput("setting_2"); 


       ilUtil::sendSuccess($pl->txt("saving_invoked"), true); 
       $ilCtrl->redirect($this, "configure"); 
      } 
      else 
      { 
       $form->setValuesByPost(); 
       $tpl->setContent($form->getHtml()); 
      } 
     } 

    } 
    ?> 

И это называется файл:

<?php 


if(!$ilDB->tableColumnExists('rep_robj_xptg_data','id')) 
{ 
    $ilDB->addTableColumn(
     'rep_robj_xptg_data', 
     'id', 
     array(
      'type'   => 'integer', 
      'length'   => 4 
     ) 
    ); 
} 
if(!$ilDB->tableColumnExists('rep_robj_xptg_data','is_online')) 
{ 
    $ilDB->addTableColumn(
     'rep_robj_xptg_data', 
     'is_online', 
     array(
      'type'   => 'integer', 
      'length'   => 4 
     ) 
    ); 
} 
if(!$ilDB->tableColumnExists('rep_robj_xptg_data','option_one')) 
{ 
    $ilDB->addTableColumn(
     'rep_robj_xptg_data', 
     'option_one', 
     array(
      'type'   => 'text', 
      'length'   => 4 
     ) 
    ); 
} 
if(!$ilDB->tableColumnExists('rep_robj_xptg_data','option_two')) 
{ 
    $ilDB->addTableColumn(
     'rep_robj_xptg_data', 
     'option_two', 
     array(
      'type'   => 'text', 
      'length'   => 4 
     ) 
    ); 
} 
if(!$ilDB->tableColumnExists('rep_robj_xptg_data','option_three')) 
{ 
    $ilDB->addTableColumn(
     'rep_robj_xptg_data', 
     'option_three', 
     array(
      'type'   => 'text', 
      'length'   => 4 
     ) 
    ); 
} 
?> 
+0

Ошибка при определении '$ ilDB' _null_. Как вы создаете этот объект? –

+0

@watcher «ILIAS предоставляет глобальный объект базы данных в переменной $ ilDB для доступа к базе данных. Все функции базы данных должны быть доступны с помощью методов этого объекта. Объект обертывает множество методов MDB2». Я не делал этого объекта. –

+0

что-то нужно сделать для этого объекта. что произойдет, если вы 'var_dump ($ ilDB);' прямо перед вашим оператором 'if'? –

ответ

2

Я решил это сделать еще один класс с именем ilconfig. он содержит эту очень важную часть:

public function initDB() { 
     global $ilDB; 
     if (!$ilDB->tableExists($this->getTableName())) { 
      $fields = array(
       'config_key' => array(
        'type' => 'text', 
        'length' => 128, 
        'notnull' => true 
       ), 
       'config_value' => array(
        'type' => 'clob', 
        'notnull' => false 
       ), 
      ); 
      $ilDB->createTable($this->getTableName(), $fields); 
      $ilDB->addPrimaryKey($this->getTableName(), array("config_key")); 
     } 

     return true; 
    } 

Я надеюсь, что это поможет другим людям, пытающимся разработать плагины в ILIAS!

Смежные вопросы