Hello,
I use this own system with routes in array with other parameters
i want to know if they are a better way, issue to do that …
my array :
$array_pages = array(
'test_zoom_url' => array(
'url' => '/test/url',
'title' => 'a',
'ariane_title' => 'b',
'desc' => 'c',
//'echo' => '',
'load_func' => 'test/url',
'twig' => '',
),
'test_zoom_code' => array(
'url' => '/test/code',
'title' => 'a',
'ariane_title' => 'b',
'desc' => 'c',
//'echo' => '',
'load_func' => 'test/code',
'twig' => '',
),
'api_auth' => array(
'url' => '/api/auth',
'title' => 'a',
'ariane_title' => 'b',
'desc' => 'c',
//'echo' => '',
'load_func' => 'api/auth',
'post' => true,
'twig' => '',
),
'api_create_live' => array(
'url' => '/api/create-live',
'title' => 'a',
'ariane_title' => 'b',
'desc' => 'c',
//'echo' => '',
'load_func' => 'api/create-live',
'post' => true,
'twig',
...
And what i do with my array
foreach ($array_pages as $key_pages => $value_pages) {
if (!empty($value_pages['post'])) {
$app->post($value_pages['url'], function ($request, $response, $args) use ($key_pages, $value_pages, $array_pages) {
include('../app/charger.php');
$body = $response->getBody();
$body->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
return $response->withStatus(201)
->withHeader("Content-Type", "application/json")
->withBody($body);
});
} else {
$app->get($value_pages['url'], function (Request $request, Response $response, $args) use ($app, $key_pages, $value_pages, $array_pages) {
//$response->getBody()->write("");
//return $response;
include('../app/charger.php');
if (!empty($value_pages['twig'])) {
$title = "title";
$desc = "desc";
$Variables = array(
'title' => $title,
'desc' => $desc,
'page_key' => $key_pages,
'var' => $from_controller ?? '',
);
//return $this->view->render($response, $value_pages['twig'], $Variables);
return $this->get('view')->render($response, $value_pages['twig'], $Variables);
}
});
I admit it’s completely hackneyed and I’ve been trying to do something simple for me, maybe it’s completely absurd and there’s a better way to get all these parameters and call them up, I’d like to please and if you’re interested.