Slim/Setup Slim environment

From Aimeos documentation

Slim
Other languages:
English 100%

After installation of the Aimeos package, you need to set up the necessary environment in your Slim application.

Aimeos requires some objects to be available (like the Aimeos context) and the routes for generating the URLs. Both are added automatically if you add these two lines right before the $app-run() statement if your ./public/index.php file:

  1. $aimeos = new \Aimeos\Slim\Bootstrap( $app, require '../src/aimeos-settings.php' );
  2. $aimeos->setup( '../ext' )->routes( '../src/aimeos-routes.php' );
  3.  
  4. // Run app
  5. $app->run();

The Aimeos Slim package uses the Twig template engine to render the templates. Therefore, you have to setup the view object with a configured Twig instance. Copy the lines below at the end of your ./src/dependencies.php file:

  1. // Twig view + Aimeos templates
  2. $container['view'] = function ($c) {
  3.     $conf = ['cache' => '../cache'];
  4.     $view = new \Slim\Views\Twig('../templates', $conf);
  5.     $view->addExtension(new \Slim\Views\TwigExtension($c->get('router'), $c->get('request')->getUri()));
  6.     return $view;
  7. };

You can use the Slim PHP template engine as well if you re-implement the existing templates in PHP, but Twig has one major advantage: Templates can inherit from a common base template, so you don't have to copy the whole HTML page into each template.

Then, you should be able to call the catalog list page in your browser. For a quick start, you can use the integrated web server that is available since PHP 5.4. Simply execute this command in the base directory of your application:

php -S 127.0.0.1:8000 -t public

Point your browser to the list page of the shop using:

http://127.0.0.1:8000/list

If that works, please continue to secure the administration interface.


<< Previous: Install the Aimeos package | Next: Secure the admin interface >>