PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 9, 2022

[FIXED] CakePHP3 Auth redirectURL route broken

 March 09, 2022     authentication, cakephp-3.0     No comments   

Issue

I have a controller with a particular method to login:

public function login() {

    if ($this->request->is('post')){
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);
            return $this->redirect($this->Auth->redirectUrl());
        }

    // not logged
    $this->Flash->error('Your username or password is incorrect');

    }
}

and default route looks like

Router::scope('/', function (RouteBuilder $routes) {
    $routes->fallbacks(DashedRoute::class);
});

after user is logged in CakePHP throws an error

Error: A route matching "/" could not be found.

None of the currently connected routes match the provided parameters. Add a matching route to config/routes.php

when IMO it should to redirect to the page (based on a related controller) from where login method was executed.

Login code is based on that tutorial.

Any thoughts?


Solution

To solve this issue:

Please update the below lines in routes.php file

Router::defaultRouteClass('DashedRoute');

Router::scope('/', function (RouteBuilder $routes) {

$routes->connect('/', ['controller' => 'users', 'action' => 'index']);

$routes->fallbacks('DashedRoute');

}); Plugin::routes();

Please do create index() in users controller. Let me know if any issue.



Answered By - Archit Patel
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing