Ho scritto un modulo per interfacciarsi con Views 3 utilizzando Drupal 7, ma quando creo una vista utilizzando la mia tabella personalizzata come origine dati, non vengono visualizzati dati. Ecco il mio schema da MySQL:Drupal 7 - Visualizzazione personalizzata con tabella personalizzata, nessun dato visualizzato
+-------------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| title | mediumtext | NO | | NULL | |
| Department | text | NO | | NULL | |
| credits | int(10) | NO | | NULL | |
| description | longtext | NO | | NULL | |
+-------------+------------+------+-----+---------+----------------+
Ed ecco l'override gancio in my_module.views.inc:
function my_module_views_data() {
$tableName = 'My_Awesome_Table';
$data = array();
$data[$tableName]['table']['group'] = t('Courses');
$data[$tableName]['table']['base'] = array(
'field' => 'id',
'title' => t('Courses'),
'help' => t("Contains courses, departments, and descriptions.")
);
$data[$tableName]['title'] = array(
'title' => t('Course name'),
'help' => t('Course name'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
$data[$tableName]['Department'] = array(
'title' => t('Course department'),
'help' => t('Course department'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
$data[$tableName]['credits'] = array(
'title' => t('Credits'),
'help' => t('Number of credit hours'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'argument' => array('handler' => 'views_handler_argument_numeric'),
'filter' => array('handler' => 'views_handler_filter_numeric'),
'sort' => array('handler' => 'views_handler_sort_numeric')
);
$data[$tableName]['description'] = array(
'title' => t('Course description'),
'help' => t('Course description'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
$data[$tableName]['id'] = array(
'title' => t('Unique identifier'),
'help' => t('Primary key for table'),
'field' => array('handler' => 'views_handler_field'),
'argument' => array('handler' => 'views_handler_argument_numeric'),
'filter' => array('handler' => 'views_handler_filter_numeric'),
'sort' => array('handler' => 'views_handler_sort_numeric'));
return $data;
}
fa qualcosa di sbagliato con il mio aspetto mappatura? Quando creo una vista, sto provando una semplice lista non formattata e sto semplicemente visualizzando ogni campo con un'etichetta. L'unico campo che mostra i dati è id
e tutti i valori id
della tabella sono presenti. Ho provato ad aggiungere un filtro alla vista in modo che il reparto corsi! = vuoto e Nome corso! = vuoto, che non ha eliminato alcun risultato (in base agli id
s visualizzati). Ecco la query Visualizzazioni sta generando:
SELECT My_Awesome_Table.title AS My_Awesome_Table_title,
My_Awesome_Table.Department AS My_Awesome_Table_Department,
My_Awesome_Table.description AS My_Awesome_Table_description,
My_Awesome_Table.credits AS My_Awesome_Table_credits,
My_Awesome_Table.id AS id
FROM {My_Awesome_Table} My_Awesome_Table
WHERE (((My_Awesome_Table.Department NOT LIKE '' ESCAPE '\\') AND
(My_Awesome_Table.title NOT LIKE '' ESCAPE '\\')))
Quando ho eseguito questo in phpMyAdmin, basta rimuovere il {
e }
da tutto My_Awesome_Table
, restituisce i risultati e non ci sono dati in ogni colonna.
Modifica: è forse importante dire che ho creato un altro modulo di visualizzazione personalizzato per una tabella diversa nello stesso database e funziona correttamente. Ho usato quel modulo come base per questo, cambiando il nome del modulo, i prefissi di funzione, ecc
so che questo è probabilmente ovvio, ma ogni volta che ho un problema come questo di solito è perché il nome della funzione 'my_module' è scritto in modo errato. – kylex
Prova a chiedere @ http://drupal.stackexchange.com/ – Strae