src/Controller/RoutesController.php
public function delete($id)
    {
        if (!$this->request->isAll(['ajax', 'post'])) {
            throw new MethodNotAllowedException();
        }

        /** @var Route $route */
        $route = $this->Routes->get($id);

        /** @var ResultSet $otherRoutes */
        $otherRoutes = $this->Routes->getOtherRoutesExcept($route->id, $route->model, $route->foreign_key, $route->language_id);

        if (!empty($otherRoutes) && $otherRoutes->count() >= 1) {
            /** @var Connection $connection */
            $connection = $this->Routes->connection();
            $connection->begin();

            $this->Routes->delete($route);
            if ($route->redirect_to === null) {
                /** @var Route $newDefaultRoute */
                $newDefaultRoute = $otherRoutes->first();
                $newDefaultRoute->set([
                    'redirect_to' => null,
                    'status_code' => null
                ]);
                $this->Routes->save($newDefaultRoute);

                $newRedirectRoutes = $otherRoutes->skip(1);
                foreach ($newRedirectRoutes as $r) {
                    $r->set([
                        'redirect_to' => $newDefaultRoute->id,
                        'status_code' => 301
                    ]);
                    $this->Routes->save($r);
                }
            }

            $connection->commit();
            $this->Flash->success(__d('wasabi_core', 'The URL <strong>{0}</strong> has been deleted.', $route->url), 'routes');
        } else {
            $this->Flash->error(__d('wasabi_core', 'The URL <strong>{0}</strong> cannot be deleted. Please create another URL first.', $route->url), 'routes');
        }

        $this->_render($route, $this->request->query('element'));
    }
public function delete($id)
    {
        if (!$this->request->isAll(['ajax', 'post'])) {
            throw new MethodNotAllowedException();
        }

        /** @var Route $route */
        $route = $this->Routes->get($id);

        /** @var ResultSet $otherRoutes */
        $otherRoutes = $this->Routes->getOtherRoutesExcept($route->id, $route->model, $route->foreign_key, $route->language_id);

        if (!empty($otherRoutes) && $otherRoutes->count() >= 1) {
            /** @var Connection $connection */
            $connection = $this->Routes->connection();
            $connection->begin();

            $this->Routes->delete($route);
            if ($route->redirect_to === null) {
                /** @var Route $newDefaultRoute */
                $newDefaultRoute = $otherRoutes->first();
                $newDefaultRoute->set([
                    'redirect_to' => null,
                    'status_code' => null
                ]);
                $this->Routes->save($newDefaultRoute);

                $newRedirectRoutes = $otherRoutes->skip(1);
                foreach ($newRedirectRoutes as $r) {
                    $r->set([
                        'redirect_to' => $newDefaultRoute->id,
                        'status_code' => 301
                    ]);
                    $this->Routes->save($r);
                }
            }

            $connection->commit();
            $this->Flash->success(__d('wasabi_core', 'The URL <strong>{0}</strong> has been deleted.', $route->url), 'routes');
        } else {
            $this->Flash->error(__d('wasabi_core', 'The URL <strong>{0}</strong> cannot be deleted. Please create another URL first.', $route->url), 'routes');
        }

        $this->_render($route, $this->request->query('element'));
    }
public function delete ( $ id ) { if ( ! $ this -> request -> isAll ( [ 'ajax' , 'post' ] ) ) { throw new MethodNotAllowedException ( ) ; } /** @var Route $route */ $ route = $ this -> Routes -> get ( $ id ) ; /** @var ResultSet $otherRoutes */ $ otherRoutes = $ this -> Routes -> getOtherRoutesExcept ( $ route -> id , $ route -> model , $ route -> foreign_key , $ route -> language_id ) ; if ( ! empty ( $ otherRoutes ) && $ otherRoutes -> count ( ) >= 1 ) { /** @var Connection $connection */ $ connection = $ this -> Routes -> connection ( ) ; $ connection -> begin ( ) ; $ this -> Routes -> delete ( $ route ) ; if ( $ route -> redirect_to === null ) { /** @var Route $newDefaultRoute */ $ newDefaultRoute = $ otherRoutes -> first ( ) ; $ newDefaultRoute -> set ( [ 'redirect_to' => null , 'status_code' => null ] ) ; $ this -> Routes -> save ( $ newDefaultRoute ) ; $ newRedirectRoutes = $ otherRoutes -> skip ( 1 ) ; foreach ( $ newRedirectRoutes as $ r ) { $ r -> set ( [ 'redirect_to' => $ newDefaultRoute -> id , 'status_code' => 301 ] ) ; $ this -> Routes -> save ( $ r ) ; } } $ connection -> commit ( ) ; $ this -> Flash -> success ( __d ( 'wasabi_core' , 'The URL <strong>{0}</strong> has been deleted.' , $ route -> url ) , 'routes' ) ; } else { $ this -> Flash -> error ( __d ( 'wasabi_core' , 'The URL <strong>{0}</strong> cannot be deleted. Please create another URL first.' , $ route -> url ) , 'routes' ) ; } $ this -> _render ( $ route , $ this -> request -> query ( 'element' ) ) ; }
Delete action
AJAX POST

@param int|string $id The route id.
@return void
Delete action AJAX POST