Jump to content

own fields dont get the input in the DB


Recommended Posts

Hello, i would like write a module with a simple textfield (for learning).

 

I had this actually, but all my input in the textfield dont be stored in db or is displayed in my textfield after safe. What ist wrong or is missed? Thx.

 

<?php

class FieldtypeTest extends FieldtypeMulti {

  /**
   * - Zwingend notwendig
   * Angaben zum Modul in PW
   */
    public static function getModuleInfo() {
        return array(
            'title' => 'Beispielmodul für Eigenentwicklungen',
            'version' => 1,
            'summary' => 'Einfache Texteingabe als Beispiel für eigene Module.',
            'requires' => '',
            );
    }

  /**
   * - Zwingend notwendig
   * alles hierin wird garantiert jedesmal ausgeführt
   */
  public function init() {
    parent::init();
  }

    /**
     * Gibt das Datenbankschema für diesen Feldtyp an
   * bei vollkommen PW untypischen Tabellenstrukturen wäre die Tabellenerstellung in der Methode ___install() möglich
     */
    public function getDatabaseSchema(Field $field) {
        $schema = parent::getDatabaseSchema($field);

        // 'data' is a required field for any Fieldtype, and we're using it to represent our 'date' field
        $schema['data'] = 'INT NOT NULL DEFAULT 0';
        // our text fields
        $schema['info1'] = 'TINYTEXT NOT NULL';
        $schema['info2'] = 'TEXT NOT NULL';

        return $schema;
    }

    /**
     * Gibt das zugehörige Eingabefeld
   * $page und $field kommen von PW (noch nicht genau erörtert woher genau)
   * $field ist in der Basisversion die ID in der DB-Tabelle "fields"  
     *
     */
    public function getInputfield(Page $page, Field $field) {
        $inputField = $this->modules->get('InputfieldTest');
        return $inputField;
    }
    
}

and this:

<?php

class InputfieldTest extends Inputfield {

public static function getModuleInfo() {
return array(
'title' => 'Inputfeld für das FieldtypeTest',
'version' => 1,
'summary' => 'siehe FieldtypeTest',
'requires' => 'FieldtypeTest',
);
}

/**
* - Zwingend notwendig für ein Inputfeld
* Erzeugt/Liefert die Ausgabe des Inputfeldes
*/
public function ___render() {

$out = "Irgendwelcher Output";

// Erzeugt ein Textfeld
$input1 = $this->modules->get('InputfieldText');
$input1->attr('id', $this->attr('name') . "_info1");
$input1->attr('name', "_info1");
$input1->class .= " InputfieldInfo1";
$input1->value = $this->value;
$out .= $input1->render();
return $out;
}

public function init() {
parent::init();
}

}
Link to comment
Share on other sites

You're missing the mandatory sleepValue() and wakeupValue() functions. These are responsable for makeing the objects data available to the database functions and for combining the data from the database to the field object.

  • Like 1
Link to comment
Share on other sites

added this code with ___sleepValue() to the first posting. I expected so an DB entry with predefined values but .... nothing. Why?

/**
* Konvertiert die Daten des Fieldtyps in ein Array wie es für die DB benötigt wird
* nach dem Muster: $kcValue[] = array('data' => "111", 'info1' => "Testeintrag", 'info2' => "Testeintrag 2");
*/
public function ___sleepValue(Page $page, Field $field, $value) {

$kcValue = array();
$kcValue[] = array('data' => "111", 'info1' => "Testeintrag", 'info2' => "Testeintrag 2");
return $kcValue;

}

Could it be possible that i need an DataWire-Object with set()-method?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...