how to use slim redirect

后端 未结 9 1458
有刺的猬
有刺的猬 2020-12-14 02:45

I have a problem. I am using slim and I have route for my main page:

$app->get(\'/\', function() use ($app) { ... 

In one of my controll

9条回答
  •  无人及你
    2020-12-14 03:09

    give your '/' route a name,

    $app = new \Slim\Slim();
    $app->get('/', function () {
           echo "root page";
        })->name('root');
    
    
    $app->get('/foo', function () use ($app) {
           $app->redirect($app->urlFor('root') );
        });
    
    $app->run();
    

    This should give you the correct url to redirect

    http://docs.slimframework.com/routing/names/ http://docs.slimframework.com/routing/helpers/#redirect

提交回复
热议问题