Hi, @odan i am using your tutorial to start my php journey and so far so good, but i don’t want to add all my config in settings file and want to split it to multiple files, but anytime i tried to add a config file to the container.php i get these errors:
Error from Browser:
This page isn’t working
example.com is currently unable to handle this request.
HTTP ERROR 500
Error from php log file:
[18-Apr-2024 14:23:56 UTC] PHP Fatal error: Uncaught Error: Array callback has to contain indices 0 and 1 in /home/primephp/public_html/primephp/config/container.php:27
And this is the code from my container.php:
<?php
use Psr\Container\ContainerInterface;
use Slim\App;
use Slim\Factory\AppFactory;
use Slim\Views\Twig;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\ConfigCache;
return [
'settings' => function () {
return require __DIR__ . '/../config/settings.php';
},
//$configDirectories = [__DIR__.'/../config'];
App::class => function (ContainerInterface $container) {
$app = AppFactory::createFromContainer($container);
// Register routes
(require __DIR__ . '/../routes/web.php')($app);
// Register middleware
(require __DIR__ . '/../app/Http/Middlewares/middleware.php')($app);
// Register routes
(require __DIR__ . '/../config/view.php')($app);
return $app;
},
Twig::class => function (ContainerInterface $container): Twig {
/** @var array<string, array<string, mixed>> $settings */
$settings = $container->get('settings');
$options = [
//'debug' => $settings['app']['debug'],
'cache' => $settings['view']['cache'],
];
/** @var string $path */
$path = $settings['view']['path'];
$twig = Twig::create($path, $options);
/** @var Translator $translator */
//$translator = $container->get(Translator::class);
//$twig->getEnvironment()->addGlobal('locale', $translator->getLocale());
//$twig->addExtension(new TranslationExtension($translator));
return $twig;
},
];
And this is my view.php file:
<?php
declare(strict_types=1);
//use function App\env;
return [
'view' => [
'path' => '../resources/views',
'cache' => false,
],
];
Thanks a lot