<?php
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Database\Driver\mysql\Connection;
class <classname> extends FormBase {
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$data = get_data(); // this just summarises getting all the data from $form_state
$result = Connection::insert('<database-name>')
->fields($data)
->execute();
Lorsque ci-dessus est exécuté en essayant de soumettre le formulaire (je l'ai quitté la méthode buildForm
pour la brièveté), je reçoisErreur fatale: Appel à la méthode non définie, dans la base de Drupal 8 insérer
Fatal error: Call to undefined method Drupal\<module>\Form\<form-name>::getDriverClass() in <drupal-root>/core/lib/Drupal/Core/Database/Connection.php on line 812
La méthode à 812 est insert
:
/**
* Prepares and returns an INSERT query object.
*
* @param string $table
* The table to use for the insert statement.
* @param array $options
* (optional) An array of options on the query.
*
* @return \Drupal\Core\Database\Query\Insert
* A new Insert query object.
*
* @see \Drupal\Core\Database\Query\Insert
*/
public function insert($table, array $options = array()) {
$class = $this->getDriverClass('Insert');
return new $class($this, $table, $options);
}
Je ne suis pas particulièrement familier avec la façon d'utiliser des techniques orientées objet en PHP, donc je don Je ne sais pas si mon problème est avec mon utilisation des espaces de noms/le mot-clé use
, ou avec la façon dont j'ai essayé d'appeler la méthode insert
, quelque chose d'autre concernant l'utilisation d'objets statiques externes, ou s'il manque quelque chose d'autre.
Quelqu'un peut-il m'aider à localiser et corriger l'erreur?
Merci.