Skip to content
PHP HTML Other
Branch: master
Clone or download
Pull request Compare This branch is 108 commits ahead, 75 commits behind slimphp:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
locale
logs
public
sql
src
templates
tests/Functional
.gitignore
CHANGELOG.md
CONTRIBUTING.md
Dockerfile
LICENSE
README.md
composer.json
composer.lock
db-model.png
deploy.sh
docker-compose.yml
doctrine
phpunit.xml

README.md

Slim Skeleton - InsanityMeetsHH

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

  • Get skeleton via $ git clone or zip download
  • Open a command prompt on your OS (if not already open) and navigate to the project folder
  • $ docker pull composer
  • $ docker run --rm --env docker=true --interactive --tty --volume $PWD:/app composer update
  • $ docker-compose build
  • $ docker-compose up -d
  • $ cp config\additional-settings.dist.php config\additional-settings.php
  • $ docker inspect slim-db | grep IPAddress set ip as Doctrine host in config\additional-settings.php
  • Open localhost:8080 for website or localhost:9999 for database gui
  • 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 imhh-slim_db_data (first remove matching container)
  • If you want to remove all container $ docker rm $(docker ps -a -q) -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

You can’t perform that action at this time.