Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ErrorController redeclaration #899

Open
elbenjaz opened this issue Oct 4, 2021 · 2 comments
Open

ErrorController redeclaration #899

elbenjaz opened this issue Oct 4, 2021 · 2 comments

Comments

@elbenjaz
Copy link

elbenjaz commented Oct 4, 2021

Hi all,

At this URL:
{Base URL}/error/whatever

The following error will appear:
"Fatal error: Cannot declare class ErrorController, because the name is already in use..." (due a double "require" in application/core/Application.php at L37 and L51).

My suggestion for fixing this issue is to change L51 in application/core/Application.php:
(before) require Config::get('PATH_CONTROLLER') . 'ErrorController.php';
(after)require_once Config::get('PATH_CONTROLLER') . 'ErrorController.php';

Greetings

@losttheplot
Copy link

I'm using huge at the core of quite a large project but I don't have this issue because I have created a method within Redirect.php as follows:

    //----------------------------------------------------------------------------------------------
    // redirect the user to a 404 page, according to whether or not they are logged in
    //----------------------------------------------------------------------------------------------
    public static function error404()
    {
        if (Session::userIsLoggedIn()) {
            
            // if the user is logged in, load the application's 404 page (shows header-bar and side-menu)
            $config = Config::getInstance();
            require $config->getApp('path_controller').'access/ErrorController.php';
            $controller = new ErrorController;
            $controller->error404();
            
        } else {
            
            // if the user is not logged in, load the application's plain 404 page (only shows dialogue box)
            $config = Config::getInstance();
            require $config->getApp('path_controller').'access/ErrorController.php';
            $controller = new ErrorController;
            $controller->loggedOut404();
            exit();
        }
    }

...and then in Application.php I have...

            } else {
                // show a 404 error page if the requested method does not exist
                Redirect::error404();
            }
        } else {
            // show a 404 error page if the requested controller does not exist
            Redirect::error404();
        }
    }

Obviously my Error Controller also looks a little different because it now has two different methods for rendering two different views, but I'm sure you get the gist.

@elbenjaz
Copy link
Author

elbenjaz commented Oct 6, 2021

Hi,

I also tried that!

(before)
require_once Config::get('PATH_CONTROLLER') . 'ErrorController.php'; $this->controller = new ErrorController; $this->controller->error404();

(after)
Redirect::to("error/error404");
Personally I prefer not to do a redirect so that the user does not "lose" the URL (similar to what Google, Amazon and many others do).

Regardless, both changes should be a reasonable solution to the issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants