Welcome Guest, Not a member yet? Register   Sign In
set 404 custom error
#1

Hi, if i set 404 error with this route (where Errors is the name the controller and show404 the method), i have a php error: Class 'Errors' not found.

Code:
$routes->set404Override(Errors::show404);

if i set error with this route the page 404 work.

Code:
$routes->set404Override(function(){echo view('show404.php');});

Why? Where i wrong?

Thanks for the support.
Reply
#2

(This post was last modified: 07-05-2020, 12:03 AM by jreklund.)

This line of code worked for me.
$routes->set404Override('App\Controllers\Errors::show404');
Reply
#3

Because you need to pass along the namespace also.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(07-04-2020, 08:41 PM)ajayamagar Wrote: This line of code worked for me.
$routes->set404Override('App\Controllers\Errors:Confusedhow404');

I did a little bit different ...

Route:
PHP Code:
<?php namespace Config;

// Create a new instance of our RouteCollection class.
$routes Services::routes();

// Load the system's routing file first, so that the app and ENVIRONMENT
// can override as needed.
if (file_exists(SYSTEMPATH 'Config/Routes.php'))
{
 require 
SYSTEMPATH 'Config/Routes.php';
}

/**
 * --------------------------------------------------------------------
 * Router Setup
 * --------------------------------------------------------------------
 */
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override(function()
{
    $header = array (
    'icon' => 'favicon',
    'css' => 'nodata',
    'title' => 'Page not found - wdeda',
    'action' => '/search/allmedia/',
    'placeholder' => 'Search'
    );
    
    
echo view('templates/headerr'$header);
    echo view('content/error_404');
    echo view('templates/footerfb');
    });
$routes->setAutoRoute(true);

/**
 * --------------------------------------------------------------------
 * Route Definitions
 * --------------------------------------------------------------------
 */

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->get('/''Home::index');

/**
 * --------------------------------------------------------------------
 * Additional Routing
 * --------------------------------------------------------------------
 *
 * There will often be times that you need additional routing and you
 * need to it be able to override any defaults in this file. Environment
 * based routes is one such time. require() additional route files here
 * to make that happen.
 *
 * You will have access to the $routes object within that file without
 * needing to reload it.
 */
if (file_exists(APPPATH 'Config/' ENVIRONMENT '/Routes.php'))
{
 require 
APPPATH 'Config/' ENVIRONMENT '/Routes.php';


The view:
PHP Code:
<!-- 20200524 -->

 <
div class="content-container">
 <
div class="message">
 <
img alt="Oops" src="/public/img/common/wd-20200416-oops.png" />
 <
span class="msgerror">ERRO 404página não encontrada.</span>
 <
h2>
 - 
What the f***!<br />
 - 
Houstonwe have a problem here.
 </
h2>
 <
h4>Às vezesisso pode acontecerNos desculpe pelo inconveniente.</h4>
 </
div>
 <
div class="links">
 <
p><a href="http://localhost">Retornar à página inicial</a></p>
 <
p><a href="mailto://[email protected]">Entrar em contato conosco para reportar um problema.</a></p>
 </
div>
 </
div


Attached Files Thumbnail(s)
   
Reply




Theme © iAndrew 2016 - Forum software by © MyBB