Creare modulo

Posts: 36
Iscritto il: 04 Nov 05

sto provando a creare un modulo per drupal sei.

<?php

<?php
/**
* Display help and module information
* @param path which path of the site we're displaying help
* @param arg array that holds the current path as would be returned from arg() function
* @return help text for the path
*/
function nodelist_help($path, $arg) {
 
$output = '';
  switch (
$path) {
    case
"admin/help#nodelist":
     
$output = '<p>'t("Displays links to nodes ") .'</p>';
      break;
  }
  return
$output;
}
?>

<?php
/**
* Valid permissions for this module
* @return array An array of valid permissions for the mailing module
*/

function nodelist_perm() {
  return array(
'access mailing content', 'administer mailing');
}
// function nodelist_perm()
?>

<?php
/**
*
* @return
*/
function nodelist_block($op='list', $delta=0) {
 
// listing of blocks, such as on the admin/block page
 
if ($op == "list") {
   
$block[0]["info"] = t("node List");
    return
$block;
  } else if (
$op == 'view') {
 
// our block content
    // content variable that will be returned for display
   
$block_content = '';

   
$result db_query("SELECT nid, title, created FROM {node} ");
    while (
$links = db_fetch_object($result)) {
     
$block_content .= l($links->title, 'node/'.$links->nid) . '<br />';
    }
   
// check to see if there was any content before setting up the block
   
if ($block_content == '') {
     
// no content from a week ago, return nothing.
     
return;
    }
   
// set up the block
   
$block['subject'] = 'node';
   
$block['content'] = $block_content;
    return
$block;
  }
}
?>

Ma quando lo attivo mi trovo
admin/build/modules/list/confirm

con un white screen.
se rivado alla pagina moduli il modulo è attivato

attivo il blocco
admin/build/block

altro white screen, però poi il blaocco lo vedo.

Dov'è l'errore?

?>


Posts: 2028
Iscritto il: 01 Gen 07
Admin di Drupal ItaliaSviluppatore DrupalDrupal Monkey. Mangio moduli e API a colazioneTraduttore

Ativa il debugger PHP così capirai al volo dove è il problema Smiling

__________________

Ciao
    Mavimo
_________________
Io mio sito su Drupal, CFD e OpenFOAM (e se vi chiedete cosa c'entrano l'uno con l'altro.. bhè, non so nemmeno io la risposta Sticking out tongue )


Posts: 36
Iscritto il: 04 Nov 05

Purtroppo l'erroe me lo da solo sull'hosting, sul mio server funziona.

Sull'hosting non riesco ad attivare il display_errors.

Se metto

php_flags display_errors On

nel file .htaccess ho errore 500


Posts: 2028
Iscritto il: 01 Gen 07
Admin di Drupal ItaliaSviluppatore DrupalDrupal Monkey. Mangio moduli e API a colazioneTraduttore

Il modulo è abbastanza banale e dovrebbe funzionare senza problemi (ne è la conferma che sul to server locale funzioni senza problemi), se non funziona sul server remoto potrebbe essere che venga riconosciuto come script maligno da qualche sistema di protezione del server, prova a chiede agli admin dei tuoi hoster.

__________________

Ciao
    Mavimo
_________________
Io mio sito su Drupal, CFD e OpenFOAM (e se vi chiedete cosa c'entrano l'uno con l'altro.. bhè, non so nemmeno io la risposta Sticking out tongue )


Posts: 36
Iscritto il: 04 Nov 05

Il modulo Syslog di Drupal mi da questo erroe:

User bonzo
Location http://###/admin/build/modules/list/confirm
Referrer
http://####/admin/build/modules
Message
Cannot modify header information - headers already sent by (output started at /###/modules/nodelist/nodelist.module:19) in /###/includes/common.inc on line 319.
Severity error
Hostname #######
Operations


Posts: 43
Iscritto il: 22 Lug 07

be', cosa c'è alla linea 19 di nodelist.module?


Posts: 43
Iscritto il: 22 Lug 07

uhm, ma tu in quel file apri e chiudi i tag php (cioè "<?php" e "?>") più volte?
se sì, allora probabilmente ti basta toglierli tutti, eccetto il primo "<?php" che deve essere la prima cosa che il file contiene (neppure uno spazio prima!)

prova e fammi sapere.

ciao, giovanni


Posts: 36
Iscritto il: 04 Nov 05

Grazie mille, così funziona.
E' una convenzione di Drupal?


nik
Posts: 52
Iscritto il: 03 Ott 07

si, il tag di chiusura non si mette:

Citazione:
PHP Code Tags
Always use
<?php

?>
to delimit PHP code, not the <? ?> shorthand. This is required for Drupal compliance and is also the most portable way to include PHP code on differing operating systems and setups.
Note that as of Drupal 4.7, the ?> at the end of code files (modules, includes, etc.) is purposely omitted. The full discussion that led to this decision is available from the no ?>
... http://drupal.org/coding-standards


Posts: 43
Iscritto il: 22 Lug 07

giusto per chiarire, il problema non erano i tag php in sé, ma il fatto che tra i tag di chiusura ed apertura c'erano dei caratteri: alla linea 19, c'era una riga vuota tra il tag ?> ed il tag <?php.
Drupal usa la funzione header(), che non funziona se un qualsiasi carattere è già stato inviato al browser.
anche solo uno spazio o un ritorno a capo provocano il messaggio "Cannot modify header information - headers already sent".
tutto qui. Eye-wink
ciao, giovanni


Posts: 36
Iscritto il: 04 Nov 05

Ok, grazie della spiegazione


Condividi contenuti