//ads:
?>
SlimExceptionHttpNotFoundException
PHP Snippet 1:
$app = AppFactory::create();
PHP Snippet 2:
$app->setBasePath("/myapp/api"); // /myapp/api is the api folder (http://domain/myapp/api)
PHP Snippet 3:
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^api/(.*)$ api/index.php/$1
PHP Snippet 4:
try {
$app->run();
} catch (Exception $e) {
// We display a error message
die( json_encode(array("status" => "failed", "message" => "This action is not allowed")));
}
PHP Snippet 5:
$app = AppFactory::create();
PHP Snippet 6:
$app->addErrorMiddleware(true, true, true);
PHP Snippet 7:
$app->setBasePath("/myapp/public/index.php");
// Define app routes
$app->get('/hello/{name}', function (Request $request, Response $response, $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");
return $response;
});
PHP Snippet 8:
$app->get('/hello/{name}', function (Request $request, Response $response, array $args) { ... }
PHP Snippet 9:
$app->get('/[my-appname]/public/hello/{name}', function (Request $request, Response $response, array $args) { .. }
PHP Snippet 10:
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();
//here i used the url change to your project name on [my-appname]
$app->get('/[my-appname]/public/hello/{name}', function (Request $request,
Response $response, array $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");
return $response;
});
$app->run();
PHP Snippet 11:
composer require slim/slim:3.*
PHP Snippet 12:
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
//use Slim\Factory\AppFactory;
require '../vendor/autoload.php';
$app = new \Slim\App;
$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");
return $response;
});
$app->run();