select('exchangePlatform', 'ep'); $query->condition('ep.id', $id); $query->fields('ep', array('id', 'titre','description','fichier')); //echo $query; //print_r((string) $query); //print_r($query->arguments()); $exchangeP = $query->execute()->fetchAll(); // Do something with your variables here. foreach ($exchangeP as $record) { // Do something with each $record. $myTitle = $record->titre; $myDescription = $record->description; $myFichier = $record->fichier; //can pass the whole /*TODO: write object class to pass instead*/ } /*TODO: write object class to pass instead*/ }catch(\Exception $error){ // Log the error. watchdog_exception('Exchange platform ', $error, t('An unknown error occurred while trying to handle exchange platform controller exchangeById. This is a generic local error ocurred. The reported error was @error', ['@error' => $error->getMessage()])); } return [ // Your theme hook name. '#theme' => 'exchange_platform_theme_hook', // Your variables. '#variable1' => $myTitle, '#variable2' => $myDescription, '#variable3' => $myFichier, ]; /*return [ '#markup' => 'Hello, Exchange Item '.$id, ];*/ } public function exchange(string $title){ //Strip the title from '-' to get the title - optional add the id# to it for simplified query //get last array item for the id //$exTitle = str_replace("-", " ", $title); //extra-control-of-machines-IEEE-AVR-19 $exchangeArray = explode("-", $title) ; $reversed = array_reverse($exchangeArray); $logged_in = \Drupal::currentUser()->isAuthenticated(); $username = \Drupal::currentUser()->getDisplayName(); $useremail = \Drupal::currentUser()->getEmail(); $id = $reversed[0]; // possible solution $this->exchangeById($id);*/ try{ //To get another database (here : 'external') $con = \Drupal\Core\Database\Database::getConnection('default','external'); $query = $con->select('exchangePlatform', 'ep'); $query->condition('ep.id', $id); //$result = db_query('SELECT * FROM person WHERE name LIKE :pattern', array( ':pattern' => db_like($prefix) . '%', )); $query->fields('ep', array('id', 'titre','description','fichier','type','tag','auteur','date','nb_note' ,'note' ,'noteHalf' ,'nb_telechargement')); $exchangeP = $query->execute()->fetchAll(); // Do something with your variables here. foreach ($exchangeP as $record) { // Do something with each $record. $myTitle = $record->titre; $myDescription = $record->description; $myFichier = $record->fichier; $type = $record->type; $tag = $record->tag; $auteur = $record->auteur; $date = $record->date; $nb_note = $record->nb_note; $note = $record->note; $noteHalf = $record->noteHalf; $nb_telechargement = $record->nb_telechargement; /*TODO: write object class to pass instead*/ } //translate the tags into an array from string $tagArr = explode(',',$tag); /*$form = \Drupal::formBuilder()->getForm('Drupal\user\Form\UserLoginForm::class'); $render = \Drupal::service('renderer'); \Drupal::service('renderer')->renderRoot($form); $login_form = $render->renderPlain($form); */ }catch(\Exception $error){ // Log the error. watchdog_exception('Exchange platform ', $error, t('An unknown error occurred while trying to handle exchange platform controller exchange(). This is a generic local error ocurred. The reported error was @error', ['@error' => $error->getMessage()])); } return [ // Your theme hook name. '#theme' => 'exchange_platform_theme_hook', // Your variables. '#ex_id' => $id, '#ex_title' => $myTitle, '#ex_description' => $myDescription, '#ex_type' => $type, '#ex_tag' => $tagArr, '#ex_fichier' => $myFichier, '#ex_auteur' => $auteur, '#ex_date' => $date, '#ex_nb_note' => $nb_note, '#ex_noteHalf' => $note, '#ex_nb_telechargement' => $nb_telechargement, '#logged_in' =>$logged_in, '#ex_username' => $username, '#ex_useremail' => $useremail, '#title' => $myTitle, '#link' => '', '#login_form' => '', //$login_form, '#attached' => [ 'library' => [ 'exchange_platform/exchange_platform-style', ], ], ]; } }The website encountered an unexpected error. Please try again later.