2016-11-27 92 views
0

我得到了一個slim demo,但我對這個並不熟悉,我在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/register功能在broswergooglefirefox

如:

localhost/index.php/register? (我測試,什麼也沒得到)

如果你需要更多的信息,請在下面提出問題。

我測試

1)本地主機/註冊

localhost/registerl

2)本地主機/ Login2身份

localhost/login2

編輯:我知道如何後提醒,在broswer,我用localhost/public/index.php訪問路線

,我訪問/路線:

enter image description here

+1

Shoudnt be localhost/register? – Mihai

+0

@Mihai我編輯了我的問題,在'firefox'中有我的測試。 – aircraft

+0

我在這裏猜測,但你需要一個獲得函數,如請求基地'/'所以克隆該功能,但與/註冊'$ app-> get..' – Mihai

回答

1

在您的情況下,您可以通過以下URL訪問/login2路線: localhost/public/index.php/login2