Cake PHP 3.5路线

时间:2019-06-13 10:30:16

标签: cakephp-3.0

我有一个控制器[1] "No1" "No2" 和一个方法ShareController

view

我有一条路线:

class ShareController extends AppController
{

    public  function beforeFilter(Event $event)
    {
    }

    public function index()
    {


    }

    public function view($id)
    {

        die('here');
    }

}

当我访问Router::defaultRouteClass(DashedRoute::class); Router::extensions(['json', 'xml']); Router::scope('/', function (RouteBuilder $routes) { $routes->connect('/forsale/:id', ['controller' => 'Share', 'action' => 'view']) ->setPatterns(['id' => '\d+']) ->setPass(['id']);; $routes->fallbacks(DashedRoute::class); }); Router::prefix('sitecontrol', function ($routes) { $routes->connect('/', ['controller' => 'Admins', 'action' => 'login']); $routes->connect('/dashboard', ['controller'=>'Admins','action'=>'dashboard']); $routes->connect('/logout', ['controller'=>'Admins','action'=>'logout']); $routes->fallbacks('InflectedRoute'); }); /** * Load all plugin routes. See the Plugin documentation on * how to customize the loading of plugin routes. */ Plugin::routes(); 时,我被重定向到:http://thewebsite/users/login?redirect=%2Fforsale%2F197

什么可能导致此重定向?我希望看到“这里”。

谢谢

1 个答案:

答案 0 :(得分:0)

由于身份验证模块,您被重定向到登录页面。由于您不允许非登录用户执行查看操作,因此您需要绕过身份验证以执行查看操作。请按如下方式修改beforefilter函数:

public function beforeFilter(Event $event)
{
    parent::beforeFilter($event);
    $this->Auth->allow('view');
}