insanitymeetshh/slim-skeleton

Slim Skeleton - InsanityMeetsHH

5.4.1 2020-02-29 19:57 UTC

README

Demo page

Included

Required

Installation with Composer (Recommended)

$ composer create-project insanitymeetshh/slim-skeleton [my-app-name]

This will install Slim and all required dependencies. Requires PHP 5.5 or newer.

Go to your project directory for following steps.

$ cd [my-app-name]

Setup database and config\additional-settings.php (only if you don't use composer create-project)

Duplicate config\additional-settings.dist.php to config\additional-settings.php. (config\additional-settings.php is useful for working with git and your local environment is different to live or to your team mates)

If you want to use not MySQL and/or your server is not 127.0.0.1 then you have to add driver and/or host in config/additional-settings.php

Change database conditions in config\additional-settings.php (without dbname).

$ php doctrine dbal:run-sql "CREATE DATABASE slim_database"

Add database name to dbname in config\additional-settings.php and run following command.

$ php doctrine orm:schema-tool:update --force

Now you've created the database tables named user and role.

The last step is to fill the table with some roles and one user

$ php doctrine dbal:import sql/all-records.sql

How to create further localisations

  • Duplicate one existing file in folder locale/ (e.g. copy locale/de-DE.php to locale/fr-FR.php)
  • Change route prefix from /de/ to /fr/ in locale/fr-FR.php
  • You can also define paths like /fr-be/ (locale/fr-BE.php) for example
  • If you want to show language in langswitch config/settings.php
  • Add case for fr/ in src/localisation.php

How to switch from example.com/de/ to de.example.com or example.de

How to use same url for all languages (like youtube or twitter)

  • (EN is default language and DE is alternative language for this example)
  • Got to config\additional-settings.php locale
  • Set 'process' => \App\Utility\LanguageUtility::LOCALE_SESSION | \App\Utility\LanguageUtility::DOMAIN_DISABLED,
  • Set up all routes in config/routes/xx-XX.php

Path generation with Locale code and Generic locale code

  • example.com/de/ = 'process' => \App\Utility\LanguageUtility::LOCALE_URL | \App\Utility\LanguageUtility::DOMAIN_DISABLED,
  • example.de = 'process' => \App\Utility\LanguageUtility::LOCALE_URL | \App\Utility\LanguageUtility::DOMAIN_ENABLED,
  • example.com (de-DE session) = 'process' => \App\Utility\LanguageUtility::LOCALE_SESSION | \App\Utility\LanguageUtility::DOMAIN_DISABLED,

It depends on your configuration what will be returned.

example.com/de/ example.de example.com (de-DE session)
locale code de-DE de-DE xx-XX
generic locale code de-DE xx-XX xx-XX
Twig PHP Twig Example PHP Example
locale code {{ lc }} LanguageUtility::getLocale() {{ path_for('user-register-' ~ lc) }} $this->router->pathFor('user-register-' . LanguageUtility::getLocale())
generic locale code {{ glc }} LanguageUtility::getGenericLocale() {{ path_for('user-login-' ~ glc) }} $this->router->pathFor('user-login-' . LanguageUtility::getGenericLocale())

ACL settings

With Geggleto ACL, routes are protected by role the current user has. By default every new route is not accessable until you give the route roles. Routes are defined in the route files (e.g. config/routes/de-DE.php). Any other resource is defined in settings.php. Inside the Twig templates you can use ACL functions has_role and is_allowed. Inside controllers you can also use this ACL functions and many more (e.g. is_allowed).

Installation with Docker

This steps works with Windows, macOS and Linux.

  • Get project via $ git clone https://github.com/InsanityMeetsHH/Slim-Skeleton.git or zip download
  • Open a command prompt on your OS (if not already open) and navigate to the project folder
  • $ npm i
  • Add "platform": {"php": "7.4.2"} to "config" in composer.json
  • $ cp config\additional-settings.dist.php config\additional-settings.php
  • Download composer.phar if not already done
  • $ php composer.phar install
  • $ docker-compose build
  • $ docker-compose up -d
  • $ docker inspect slim-db search for IPAddress from DIRNAME_default (at the bottom) and set IP (e.g. 172.20.0.2 often by me) as Doctrine host in config\additional-settings.php
  • Open localhost:3050 for website or localhost:9999 for database gui
  • Adminer login: user = root, pass = rootdockerpw, host = IP from IPAddress
  • If you want to remove a container $ docker rm [container-name] -f e.g. $ docker rm slim-db -f
  • If you want to remove a volume $ docker volume rm [volume-name] e.g. $ docker volume rm DIRNAME_db_data (first remove matching container)
  • If you want to remove all container $ docker rm slim-db slim-webserver slim-adminer -f
  • If you want to remove all volumes $ docker volume prune (first remove all container)

Troubleshooting

In some cases you'll get the error message "Internal Server Error".

If this happened, go to public/.htaccess and enable RewriteBase /.

If project is in sub directory then RewriteBase /project/public/.

Sources

Recommended