insanitymeetshh / slim-skeleton
Slim Skeleton - InsanityMeetsHH
Installs: 19
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 447
Open Issues: 0
Type:project
Requires
- php: >=5.5.9
- doctrine/orm: ^2.5
- geggleto/psr7-acl: ^1.3
- google/recaptcha: ^1.2
- monolog/monolog: ^1.17
- nochso/html-compress-twig: ^2.0
- paragonie/random_compat: >=1 <9.99
- phpgangsta/googleauthenticator: dev-master
- slim/csrf: ^0.8.2
- slim/flash: ^0.4.0
- slim/slim: ^3.1
- slim/twig-view: ^2.3
- symfony/console: ^3.0|^4.0
Requires (Dev)
- phpunit/phpunit: >=4.8 < 6.0
- dev-master
- 5.x-dev
- 5.4.1
- 5.4.0
- 5.3.0
- 5.2.0
- 5.1.1
- 5.1.0
- 5.0.9
- 5.0.8
- 5.0.7
- 5.0.6
- 5.0.5
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.x-dev
- 4.3.2
- 4.3.1
- 4.3.0
- 4.2.2
- 4.2.1
- 4.2.0
- 4.1.0
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.x-dev
- 3.5.0
- 3.4.0
- 3.3.0
- 3.2.2
- v3.2.1
- v3.2.0
- 3.1.4
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.x-dev
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.0
- 1.1.0
- 1.0.1
- 1.0.0
- dev-develop
- dev-production
This package is auto-updated.
Last update: 2022-07-12 01:39:32 UTC
README
Included
- Slim 3
- Slim Twig View 2
- Slim CSRF 0.8
- Slim Flash 0.4
- Monolog 1
- Doctrine ORM 2
- Geggleto ACL 1
- Google Authenticator
- Google reCAPTCHA 1
- HTML Compress Twig Extension
Required
- PHP >= 5.5.9
- MySQL (pdo_mysql)
- Docker (for installation with Docker)
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. copylocale/de-DE.php
tolocale/fr-FR.php
) - Change route prefix from
/de/
to/fr/
inlocale/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/
insrc/localisation.php
How to switch from example.com/de/ to de.example.com or example.de
- (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_URL | \App\Utility\LanguageUtility::DOMAIN_ENABLED,
- Enter your domains in
active
- Go to
config/routes/de-DE.php
- Remove
/de
from everyroute
- Go to
config/routes/xx-XX.php
- Insert all routes where the config is equal in
config/routes/en-US.php
andconfig/routes/de-DE.php
- Remove these equal routes in
config/routes/en-US.php
andconfig/routes/de-DE.php
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"
incomposer.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 forIPAddress
fromDIRNAME_default
(at the bottom) and set IP (e.g. 172.20.0.2 often by me) as Doctrinehost
inconfig\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/
.