Patching error.php with Dynamic404
Dynamic404 makes use of a core hack to do what it does: It replaces the file templates/system/error.php. Unfortunately, there is no other way to accomplish the task - no plugin event, no library override. However, Dynamic404 patches this file but also creates a backup copy.
Automatic and manual patching
When installing Dynamic404, it automatically patches the file. This means that the following file:
templates/system/error.php
is copied to a backup-location:
templates/system/error.before-dynamic.phpAnd next, the new Dynamic404 patch is copied to:
templates/system/error.php
On the Dynamic404 Setup-page within the Joomla! Administrator, you can reverse the patch or apply the patch again. When uninstalling Dynamic404, the patch is reversed automatically. The error.php file is replaced with a Dynamic404 patch located here:
components/com_dynamic404/dynamic404.php
Template overrides
With Joomla! templating, it's possible to create your own custom 404 pages. This is accomplished by adding the file error.php to your own Joomla! template and modify it there - for instance add styling or images to the 404 page.
Custom error page in Joomla!
If your Joomla! Template is already using its own error.php file or custom error page, this means that the Dynamic404 file is not used, so actually Dynamic404 is not doing anything at all.
To use Dynamic404 in this case, you need to either remove the error.php file from your template, overwrite it with the Dynamic404 patch-file, or add the necessary PHP-code of the Dynamic404 error.php file to your own.
If you are using Dynamic404 for automatically redirecting to another page, the templates error-file is of no use. But if you have disabled Dynamic404 redirects, the custom error-file in your Joomla! Template could be used to display a 404-page which could be styled according to your template.
PHP-code of Dynamic404
If you decide to write your own error-file, we highly recommend to take a look at the file components/com_dynamic404/dynamic404.php for the necessary PHP-code. The following code gives you some impression of what to look for:
// Include the 404 Helper
require_once JPATH_ADMINISTRATOR.DS.'components'.DS.'com_dynamic404'.DS.'helpers'.DS.'helper.php';
// Instantiate the helper with the argument of how many matches to show
$helper = new Dynamic404Helper(5);
// Log the 404 entry (optional)
$helper->log();
// Get the possible matches
$matches = $helper->getMatches();
// Get the last segment - nice for searching
$urilast = $helper->getLast();
// Redirect to the first found match
$helper->doRedirect();
// Ouput
foreach($matches) {
echo $item->url;
echo $item->name;
echo $item->rating;
}
Created on Friday, 11 September 2009Modified on Sunday, 14 February 2010
More tutorials in this section
- Example redirect with Dynamic404
- Dynamic404 redirection rules
- Patching error.php with Dynamic404
- Using Dynamic404 with VirtueMart
- Installing and configuring Dynamic404
- Configuration-options for Dynamic404
