Typolight / Contao CMS: Reihenfolge der imports

(Kommentare: 2)

Lustige PHP-Fehlermeldung "Fatal error: Exception thrown without a stack frame in Unknown  on line 0", als ich eine eigene Frontend-Klasse für Typolight (jetzt Contao) schreiben wollte - z.B. eine Klasse für eigenes Ajax-Handling.
Die Fehlermeldung hat zu tun mit dem Zeitpunkt, wann die Exception geworfen wird bzw. mit Exception Handler Klassen (mehr Infos zu Exceptions und Exception-Handlern bei php.net). In meinem Fall wurde die Exception geworfen / erzeugt in FrontendUser::__desctruct() in der Datenbank-Abfrage, wenn FrontendUser nach parent::__construct() Konstruktor aufgerufen wird... Schau an...

Richtige Reihenfolge also:

class AjaxFront extends Frontend {

    public function __construct() {
        $this->import('FrontendUser', 'User'); 
        parent::__construct();
        $this->User->authenticate();
        $this->loadLanguageFile('default');
    }
}    


Edited / added 2012-03-07: The issue was the funny error message "Fatal error: Exception thrown without a stack frame in Unknown on line 0" at the end of a page rendered by my own Frontend class / script.
The problem was: In constructor of the Frontend class: first call parent::__construct(), then import FrontendUser.
The solution was: In constructor of the Frontend class: first import FrontendUser, then call parent::__construct().

Complete example:

<?php

define('TL_MODE', 'FE');
require('system/initialize.php');

class AjaxFront extends Frontend {

public function __construct() {
$this->import('FrontendUser', 'User'); // import FrontendUser before parent::__construct, otherwise you will get the error message "Fatal error: Exception thrown without a stack frame in Unknown on line 0" parent::__construct();
$this->User->authenticate();

$lang = $this->Input->get('language');

if ($lang) $GLOBALS['TL_LANGUAGE'] = $lang;
else $GLOBALS['TL_LANGUAGE'] = 'en';

$this->loadLanguageFile('default');
}

public function run() {
echo "username: " . $this->User->username . "<br />\n";
echo '$GLOBALS["TL_LANG"]["DAYS"][0]: ' . $GLOBALS['TL_LANG']['DAYS'][0]. "<br />\n";
}
}

$objAjax = new AjaxFront();
$objAjax->run();

?>
 

The output is:
username: webdecker
$GLOBALS["TL_LANG"]["DAYS"][0]: Sunday
... depending on the request param language and whether a user webdecker is logged in (the case here) to the website or not.
If I flip the first two lines in the contructor then the above mentioned error message occurs at the end of the page.

The error message with its "no-information" had to do with the time the exception was thrown and when/how it is handled, see  http://php.net/manual/en/function.set-exception-handler.php...


Zurück

Kommentare

Kommentar von Paolo |

How you have solved this problem ?

Thank you
Paolo

Kommentar von webdecker |

updated article, hope that helps...

Einen Kommentar schreiben