Skip to content

Documentation on stop events and redirects #8044

@mirko-pagliai

Description

@mirko-pagliai

There is nothing in the documentation about stopping events when used with redirects.

Here (Controllers) we find a link to stopping events:
https://book.cakephp.org/5/en/controllers.html#controller-callback-methods

Which then leads to this section:
https://book.cakephp.org/5/en/core-libraries/events.html#stopping-events

Moreover, I found this (Components):
https://book.cakephp.org/5/en/controllers/components.html#using-redirects-in-component-events
So actually there is something, but it is probably (?) an obsolete example and described in relation to the components only.
Even in the upper section, there is probably something obsolete (see description for beforeRedirect, where it says it can return false)

In my opinion, instead, something like this should be documented:

public function beforeFilter(EventInterface $event): void
{
    if ($needsStopAndRedirect) {
        $event->stopPropagation();

        $this->redirect('/');

        return;
    }

    //This code should be executed only if `$needsStopAndRedirect` is false
    // ...
}

Also because I'm not sure that this is the correct procedure either.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions