404 Error page

Rigo

New Member
When I delete a campaign but still check thru the old links, it obviously redirects me to the 404 error page. I have my own custom 404 page and would like to implement it to the newsletter 404. How do I do this? Where is this file or location?

Thank you in advance.
 

Attachments

  • Screenshot_2020-12-29 Error 404 .png
    Screenshot_2020-12-29 Error 404 .png
    6.8 KB · Views: 7
Unfortunately, currently there is no way to override our 404 page. In future we might add a hook for this, but now we have nothing there.
 
I wanted to also do a custom 404 page. I found the error.php in apps/frontend/view/site/error.php. This seems to do nothing.

Any chance of allowing custom error pages.
 
@mike-gcs follow these steps:

Create a new file in apps/frontend/controllers and name it MyerrorController.php with this content in it:
PHP:
<?php declare(strict_types=1);
if (!defined('MW_PATH')) {
    exit('No direct script access allowed');
}

class MyerrorController extends Controller
{
    public $layout = 'my-error';
    
    public function actionError()
    {
        if ($error = app()->getErrorHandler()->error) {
            if (request()->getIsAjaxRequest()) {
                echo html_encode((string)$error['message']);
            } else {
                $this->setData([
                    'pageMetaTitle'         => t('app', 'Error {code}!', ['{code}' => (int)$error['code']]),
                    'pageMetaDescription'   => html_encode((string)$error['message']),
                ]);
                $this->render('error', $error);
            }
        }
    }
}

Copy /apps/frontend/views/site into /apps/frontend/views/myerror

Copy /apps/frontend/views/layouts/main.php into /apps/frontend/views/layouts/my-error.php

Then copy your /apps/frontend/config/main.php into /apps/frontend/config/main-custom.php and make sure it has only this content:
PHP:
<?php declare(strict_types=1);
if (!defined('MW_PATH')) {
    exit('No direct script access allowed');
}

return [
    'components' => [
        'errorHandler' => [
            'errorAction'   => 'myerror/error',
        ],
    ],
];

So to recap:
1. You created a new controller, MyerrorController.php in /apps/frontend/controllers/
2. You created your own layout file in /apps/frontend/views/layouts
3. You created your own error view in /apps/frontend/views/myerror
4. You created a custom config to load your custom controller

This all is safe on upgrades.
 
Back
Top