0
我得到了一個slim demo,但我對這個並不熟悉,我在routes.php
中可以看到有很多route
的文件。如何訪問苗條的路線?
左邊是dir
結構,右邊是routes.php
。
這是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
功能在broswer
如google
或firefox
?
如:
localhost/index.php/register
? (我測試,什麼也沒得到)
如果你需要更多的信息,請在下面提出問題。
我測試
1)本地主機/註冊
2)本地主機/ Login2身份
編輯:我知道如何後提醒,在broswer,我用localhost/public/index.php
訪問路線
,我訪問/
路線:
Shoudnt be localhost/register? – Mihai
@Mihai我編輯了我的問題,在'firefox'中有我的測試。 – aircraft
我在這裏猜測,但你需要一個獲得函數,如請求基地'/'所以克隆該功能,但與/註冊'$ app-> get..' – Mihai