如何访问苗条的路线?

时间:2016-11-27 10:18:52

标签: php slim

我得到了一个苗条的演示,但我对此并不熟悉,我可以在routes.php中看到文件中有很多route

左边是dir结构,右边是routes.php

The framework of dir

这是routes.php代码:

<?php
// Routes

use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use LeanCloud\LeanObject;
use LeanCloud\LeanQuery;
use LeanCloud\LeanUser;
use LeanCloud\LeanACL;

$app->get('/', function(Request $request, Response $response) {
    if (!array_key_exists('status', $request->getQueryParams())) {
        $status = '0';
    } else {
        $status = $request->getQueryParams()['status'];
    }
    $user = LeanUser::getCurrentUser();

    $query = new LeanQuery('Todo');
    $query->limit(20)->addDescend('createdAt')->_include('owner');
    if ($status === '0') {
        $query->equalTo('done', false);
    } else {
        $query->equalTo('done', true);
    }
    $todos = $query->find();

    return $this->renderer->render($response, 'index.phtml', [
    'user' => $user,
    'status' => $status,
    'todos' => $todos,
    ]);
});

$app->post('/register', function(Request $request, Response $response) {
    $data = $request->getParsedBody();
    $user = new LeanUser();
    $user->setUsername($data['name']);
    $user->setPassword($data['password']);
    try {
      $user->signUp();
    } catch (\LeanCloud\CloudException $e) {
      return $this->renderer->render($response, 'register.phtml', ['error' => $e]);
    }
    return $response->withStatus(302)->withHeader('Location', '/');
});

//测试
$app->get('/login2', function() {
    echo "login2";
});

//$app->get('/login3', );

我的要求很简单,如何调用/login2中的/registerbroswer函数,例如googlefirefox

例如:

localhost/index.php/register? (我测试,什么都没有)

如果您需要更多信息,请在问题下方提交。

我的测试

1)本地主机/注册

  

localhost/registerl

2)本地主机/ Login2身份

  

localhost/login2

编辑:我知道如何访问路线

提醒后,在broswer中,我使用localhost/public/index.php,我访问了/路线:

  

enter image description here

1 个答案:

答案 0 :(得分:1)

在您的情况下,您可以使用以下网址访问/login2路线: localhost/public/index.php/login2