[phpBB Debug] PHP Warning: in file [ROOT]/ext/tas2580/seourls/event/listener.php on line 213: Undefined array key "FORUM_NAME"
REDAXO Forum • Modul zeigt Fehler ""Call to a member function isStartArticle() on null""
Seite 1 von 1

Modul zeigt Fehler ""Call to a member function isStartArticle() on null""

Verfasst: 1. Dez 2017, 18:20
von katematsuda
Ich versuche ein Modul zu erstellen das jeweils einige Artikel bis auf Startartikel ausliest und ausgibt. Am Ende der Ausgabe soll dann ein Link erscheinen, der z.B. die nächsten 5 Artikel anzeigt, bzw. zu den fünf voringen verlinkt. Das ganze so lange bis zum Ende der Artikel.

Ich habe das Modul versucht für REDAXO5 anzupassen, aber obwohl ich keine Syntaxfehler erhalte gibt es einen Laufzeitfehler "Call to a member function isStartArticle() on null" sobald ich die Seite aufrufe in der das Modul enthalten ist. In der Schleife in der Mitte ist der Aufruf $article->isStartArticle() . Was mache ich da falsch?

Code: Alles auswählen

$articles = array();

foreach ( $cats as $catId) {
  $cat = rex_category::get( $catId);
 
  // CatIds die nicht funktionieren aussortieren
  if( $cat === null) {
     continue;
  }

  $cat_articles = $cat->getArticles( true);

  foreach ( $cat_articles as $ooarticle) {
     // keine Startartikel anzeigen
    if ( $article->isStartArticle()) {
       continue;
     }

     // Damit keine Endlosschleife passiert, den Artikel der die Pagination setzt überspringen
     if ( rex_article::getCurrentId() == REX_ARTICLE_ID) {
        continue;
     }
     $articles[] = $rex_article;
  }
}

Re: Modul zeigt Fehler ""Call to a member function isStartArticle() on null""

Verfasst: 1. Dez 2017, 21:28
von runstop64
Hi,

im for Befehl lautet dein Variablenname $ooarticle. Im Folgenden fragst du jedoch $article ab. Später dann $rex_article. Die Variable muss überall gleich heißen.

Re: Modul zeigt Fehler ""Call to a member function isStartArticle() on null""

Verfasst: 1. Dez 2017, 21:31
von runstop64
Übrigens enthalten rex_article::getCurrentId()und REX_ARTICLE_ID den gleichen Wert. Du willst hier wohl mit $article->getId() vergleichen (bzw. einer der anderen Variablennamen).

Re: Modul zeigt Fehler ""Call to a member function isStartArticle() on null""

Verfasst: 2. Dez 2017, 01:13
von katematsuda
Danke für die Hinweise auf die Namensfehler! Jetzt sind die Laufzeitfehler auch weg. Irgendwo muss aber noch ein Logikfehler sein, oder ein Fehler beim Anpassen an REDAXO5 . Er arbeitet alles ab, findet aber immer nur 0 Artikel, obwohl einige angelegt sind. Vielleicht fällt es jemandem auf , ich bin im Moment zu blind dafür.

Das Modul:

Code: Alles auswählen

<?php

// Nur im Frontend
if (!rex::isBackend()):

if(!function_exists('sortArticlesByCreateDate'))
{
// Sortierfunktion
  function sortArticlesByCreateDate( $artA, $artB) {
     $createA = $artA->_createdate;
     $createB = $artB->_createdate;

     if ( $createA == $createB) {
        return 0;
     }

     return $createA > $createB ? -1 : 1;
  }
}

$start = !empty($_GET['start']) ? (int) $_GET['start'] : 0; // Startitem
$offset = 5; // 5 Items pro Seite
$cats = array( REX_CATEGORY_ID); // alle Kategorien die Du "indizieren" willst

$articles = array();

foreach ( $cats as $catId) {
  $cat = rex_category::get( $catId);

  // CatIds die nicht funktionieren aussortieren
  if( $cat === null) {
     continue;
  } 
  $cat_articles = $cat->getArticles( true);

  foreach ( $cat_articles as $ooarticle) {  echo'1';
     // keine Startartikel anzeigen
    if ( $ooarticle->isStartArticle()) { 
       continue;
     }

     // Damit keine Endlosschleife passiert, den Artikel der die Pagination setzt überspringen
     if ( $ooarticle->getCurrentId() == REX_ARTICLE_ID )

 {
        continue;
     }
     $articles[] = $ooarticle;
  }
} 
$articles_length = count( $articles); 

//Sortieren nach Erstellungsdatum
if ( $articles_length > 0) {

   usort( $articles, "sortArticlesByCreateDate");
}

$article_list = array_slice( $articles, $start, $offset);
foreach ( $article_list as $ooarticle) {
 
  $artId = $ooarticle->getCurrentId();

  $article = new article( $artId);
  echo $article->getArticle();
  echo '<br><br><br><br><br><br><br><br><br><br>';
 
}

$prevStart = $start - $offset;
if ( $prevStart < 0)
{
   $prevStart = '';
}

$nextStart = $start + $offset;
if ( $nextStart >= $articles_length)
{
   $nextStart = '';
}



// Vorherige Seite Link
if ( $prevStart !== '') {
  echo '<a href="'.  rex_getUrl( '', '', array('start'=>$prevStart)).'"> < back </a>';
}

// Nächste Seite
if ( $nextStart !== '') {
  echo '<a href="'.  rex_getUrl( '', '', array('start'=>$nextStart)).'"> more > </a>';
}

endif;

?>

Re: Modul zeigt Fehler ""Call to a member function isStartArticle() on null""

Verfasst: 2. Dez 2017, 03:28
von runstop64
$ooarticle->getId() nicht $ooarticle->getCurrentId()

Re: Modul zeigt Fehler ""Call to a member function isStartArticle() on null""

Verfasst: 2. Dez 2017, 10:51
von katematsuda
Danke, aber das liegt das Problem anscheinend nicht. Ich habe den Verdacht dass $cat = rex_category::get( $catId); kein Kategorien findet.
Früher war das OOCategory::getCategoryById() .... damit klappte es.

Re: Modul zeigt Fehler ""Call to a member function isStartArticle() on null""

Verfasst: 2. Dez 2017, 14:30
von runstop64
Es sollte immer die Kategorie gefunden werden, in der der Artikel mit diesem Modul liegt.
mit

Code: Alles auswählen

dump($variable)
kannst du den jeweiligen Variableninhalt ausgeben und debuggen.

Bei der Artikelausgabe muss es statt

Code: Alles auswählen

new article($artId)
so lauten:

Code: Alles auswählen

new rex_article_content($artId)

Re: Modul zeigt Fehler ""Call to a member function isStartArticle() on null""

Verfasst: 2. Dez 2017, 15:19
von katematsuda
Aha! Danke ... die REDAXO5 Doku sagt dazu irgendwie nichts...

Mit dieser Änderung kommt etwas raus, aber auch folgende Fehlermeldung:


Notice: Undefined property: rex_article::$_createdate in rex:///module/26/output on line 10
Notice: Undefined property: rex_article::$_createdate in rex:///module/26/output on line 11

Zu createdate finde ich leider keine Hinweise in der Doku .... weiss es jemand?

Re: Modul zeigt Fehler ""Call to a member function isStartArticle() on null""

Verfasst: 3. Dez 2017, 12:32
von runstop64
Das liegt an der Sortierfunktion im Modul.
Versuche es statt

Code: Alles auswählen

...->_createdate
mit

Code: Alles auswählen

...->getValue(„createdate“)

Re: Modul zeigt Fehler ""Call to a member function isStartArticle() on null""

Verfasst: 3. Dez 2017, 13:21
von katematsuda
Vielen Dank an Daniel!

Endlich macht das Modul was es soll. Das war leider eine schwere Geburt. Ich weiss nicht mehr woher das ursprüngliche Modul überhaupt stammt, leider sind die Modul-Download Seiten von früher verschwunden so dass es nicht überprüft werden kann. Dennoch Danke an den ursprünglichen Autor und an alle Helfer hier.

Falls jemand so etwas gebrauchen kann hier der momentan funktionierende Code:

Code: Alles auswählen

<?php

// Nur im Frontend
if (!rex::isBackend()):

if(!function_exists('sortArticlesByCreateDate'))
{
// Sortierfunktion
  function sortArticlesByCreateDate( $artA, $artB) {
     $createA = $artA->getValue('createdate');
     $createB = $artB->getValue('createdate');

     if ( $createA == $createB) {
        return 0;
     }

     return $createA > $createB ? -1 : 1;
  }
}

$start = !empty($_GET['start']) ? (int) $_GET['start'] : 0; // Startitem
$offset = 5; // 5 Items pro Seite
$cats = array( REX_CATEGORY_ID); // alle Kategorien die Du "indizieren" willst

$articles = array();

foreach ( $cats as $catId) {
  $cat = rex_category::get( $catId);
 
  // CatIds die nicht funktionieren aussortieren
  if( $cat === null) {
     continue;
  }

  $cat_articles = $cat->getArticles( true);

  foreach ( $cat_articles as $ooarticle) {
     // keine Startartikel anzeigen
    if ( $ooarticle->isStartArticle()) {
       continue;
     }

     // Damit keine Endlosschleife passiert, den Artikel der die Pagination setzt ?berspringen
     if ( $ooarticle->getId() == REX_ARTICLE_ID) {
        continue;
     }
     $articles[] = $ooarticle;
  }
}
$articles_length = count( $articles);

// Sortieren nach Erstellungsdatum
if ( $articles_length > 0) {

   usort( $articles, "sortArticlesByCreateDate"); 
}

$article_list = array_slice( $articles, $start, $offset);

foreach ( $article_list as $ooarticle) {
  $artId = $ooarticle->getId();

  $article = new rex_article_content( $artId);
  echo $article->getArticle();
  echo '<br><br><br><br><br><br><br><br><br><br>';
 
}

$prevStart = $start - $offset;
if ( $prevStart < 0)
{
   $prevStart = '';
}

$nextStart = $start + $offset;
if ( $nextStart >= $articles_length)
{
   $nextStart = '';
}



// Vorherige Seite Link
if ( $prevStart !== '') {
  echo '<a href="'.  rex_getUrl( '', '', array('start'=>$prevStart)).'"> < back </a>';
}

// N?chste Seite
if ( $nextStart !== '') {
  echo '<a href="'.  rex_getUrl( '', '', array('start'=>$nextStart)).'"> more > </a>';
}

endif;

?>