aircraft aircraft - 5 days ago 6
PHP Question

How to access the routes in slim?

I get a slim demo, but I am not familiar to that, I can see in the

routes.php
there are many
route
in the file.

Left is the
dir
structure, right is the
routes.php
.

The framework of dir

This is
routes.php
code:

<?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', );


My requirment is easy, how can I call the
/login2
or
/register
functions in the
broswer
such as
google
or
firefox
?

eg:

localhost/index.php/register
? (I test, get nothing)

If you need more infomation, please commit below the question.

My test

1)localhost/register


localhost/registerl


2)localhost/login2


localhost/login2


EDIT: I know how to access the route

after the remind, in broswer , I use
localhost/public/index.php
, I access the
/
route:


enter image description here

Answer

In your case you can access /login2 route with following URL: localhost/public/index.php/login2

Comments