API15

JError/customErrorPage: Difference between revisions

From Joomla! Documentation

m removing red link to edit, no existant pages
m preparing for archive only
 
Line 77: Line 77:


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=customErrorPage
  category=customErrorPage
  category=JError
  category=JError
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*

Latest revision as of 00:34, 25 March 2017

Description

Display a custom error page and exit gracefully

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

customErrorPage(&$error)
Parameter Name Default Value Description
&$error $error Exception object

Returns

void

Defined in

libraries/joomla/error/error.php

Importing

jimport( 'joomla.error.error' );

Source Body

function customErrorPage(& $error)
{
        // Initialize variables
        jimport('joomla.document.document');
        $app        = & JFactory::getApplication();
        $document       = & JDocument::getInstance('error');
        $config         = & JFactory::getConfig();

        //Get the current language direction
        $language = &JFactory::getLanguage();
        if ($language->isRTL()){
        $dir ="rtl";
        }
        else {
        $dir ="ltr";
        }

        // Get the current template from the application
        $template = $app->getTemplate();

        // Push the error object into the document
        $document->setError($error);

        @ob_end_clean();
        $document->setTitle(JText::_('Error').': '.$error->code);
        $document->setLanguage($language->getTag());
        $document->setDirection($dir);
        $data = $document->render(false, array (
                'template' => $template,
                'directory' => JPATH_THEMES,
                'debug' => $config->getValue('config.debug')
        ));

        JResponse::setBody($data);
        echo JResponse::toString();
        $app->close(0);
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

Code Examples