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

ActionController: Document how to throw 404 #3866

Open
cweiske opened this issue Jan 9, 2024 · 0 comments
Open

ActionController: Document how to throw 404 #3866

cweiske opened this issue Jan 9, 2024 · 0 comments

Comments

@cweiske
Copy link
Contributor

cweiske commented Jan 9, 2024

Current behavior

The "ActionController" page does not talk about how to properly throw a 404 error when e.g. a record cannot be found in the database.

Expected behavior/output

Example code how to throw a 404 page.

use TYPO3\CMS\Core\Http\ImmediateResponseException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\ErrorController;

if ($record === null) {
    $response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
        $GLOBALS['TYPO3_REQUEST'], 'Record not found'
    );
    throw new ImmediateResponseException($response, 1704787250);
}

Links

https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ExtensionArchitecture/Extbase/Reference/Controller/ActionController.html

TYPO3 versions

12, main

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

1 participant