Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing tutorial.md #34

Merged
merged 3 commits into from Mar 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
115 changes: 72 additions & 43 deletions doc/TUTORIAL.md
Expand Up @@ -15,7 +15,7 @@ This book will cover how to build applications with ATK 9, this book will not di

## Let's dive in: Building our first app

Let build's a conference app our app will allow us to register the Speaker, the onference titles, and the conference attendants for each conference.
Let build's a conference app our app will allow us to register the Speaker, the conference titles, and the conference attendants for each conference.

### Getting the necesary tools.

Expand Down Expand Up @@ -53,7 +53,7 @@ Finally, you should put composer in the path to be readily available when needed

`sudo mv composer.phar /usr/local/bin/composer`

Now we are gonna need to clone the Sintattica/atk-skeleton project. The skeleton project is an empty project to serve as boiler plate for your own project. In order to graba a copy you will need git:
Now we are gonna need to clone the Sintattica/atk-skeleton project. The skeleton project is an empty project to serve as boiler plate for your own project. In order to grab a copy you will need git:

`
git clone https://github.com/Sintattica/atk-skeleton.git conference
Expand All @@ -63,16 +63,20 @@ This should download a copy of the skeleton project in a directory called **conf

```
conference/
├── atk-skeleton.sql
├── composer.json
├── config
│   ├── app.php
│   └── atk.php
│   ├── atk.php
│   ├── parameters.dev.php
│   ├── parameters.dist.php
│   ├── parameters.prod.php
│   ├── parameters.staging.php
├── README.md
├── languages
│   ├── en.php
│   └── it.php
├── src
│   ├── atk-skeleton.sql
│   ├── languages
│   │   ├── en.php
│   │   └── it.php
│   └── Modules
│   ├── App
│   │   ├── languages
Expand All @@ -92,14 +96,17 @@ conference/
└── web
├── bundles
│   └── atk -> ../../vendor/sintattica/atk/src/Resources/public
└── index.php
├── index.php
└── images
├── brand_logo.png
└── login_logo.png
```

Let's take a quick look to some files and directories:

- composer.json: It is the composer dependencies file, any time you need a new software librry you should add its name here and run **composer update**.
- composer.json: It is the composer dependencies file, any time you need a new software library you should add its name here and run **composer update**.
- The config direcory contains the configuration files.
- The src directory: Our work will go mainly in this directory, this is the diretory where our application sources will reside, more specifically in the modules directory.
- The src directory: Our work will go mainly in this directory, this is the directory where our application sources will reside, more specifically in the modules directory.
- The var directory is for temporary files
- The web directory is the directory that will need to be served by a web server (Apache, Nginx, Lighttpd or any other).

Expand Down Expand Up @@ -132,68 +139,90 @@ And :

`grant all on conference.* to conference@localhost identified by 'conference';`

If you take a look around the skeleton project maybe you noticed a file called **atk-skeleton.sql** lying in the **src/** directory, this file contains the table definitions for ATK security system, your database should have these tables, we will create them with:
If you take a look around the skeleton project maybe you noticed a file called **atk-skeleton.sql** lying in the root directory, this file contains the table definitions for ATK security system, your database should have these tables, we will create them with:

`mysql -u root -p conference < src/atk-skeleton.sql `
`mysql -u conference -p conference < atk-skeleton.sql `

Now, we will need to configure our application.

### Configuring our application

If you take a look at the root directory of our project you will see a file called **.env.example**. You can set ATK options and parameters by setting environmental variables, i.e. you can set the database user and password by setting two environment vars :

- DB_USER
- DB_PASSWORD

In linux it can be achieved by issuing:

`export DB_USER=root` and `export DB_PASSWORD=xxxx`

But these setting will last until the job ends, so, how to avoid having to re-enter all the parameters in each session?. That is the job of the .env file. You can set your environment variables in the file and ATK will load all the env vars for you.
The **.env.example** file is to be copied to a customized **.env** with the proper values edited in.
So copy it wit:

`cp .env.example .env`
Main configuration options are specified in **config/** directory. Specifically, the parameters.xxx.php files (where xxx stands for dev, dist, prod or staging) contains per-site variables. For this tutorial, we'll work with "dev" environment so you'll have to specify values in **config/parameters.dev.php**.

Let's take a look at the contents of the file:

```
DB_NAME=atk-skeleton
DEBUG_LEVEL=1

# adminpwd
ADMIN_PASSWORD="$2y$10$H17EjSHXZckjBoIWEd.SUe7pHcDqRH5RZhpu.VVv3H48M5Im7Z0Tq"
return [
'atk' => [

'identifier' => 'atk-skeleton-dev',

'db' => [
'default' => [
'host' => 'localhost',
'db' => 'atk-skeleton',
'user' => 'root',
'password' => '',
'charset' => 'utf8',
'driver' => 'MySqli',
],
],

'debug' => 1,
'meta_caching' => false,
'auth_ignorepasswordmatch' => false,
'administratorpassword' => '$2y$10$erDvMUhORJraJyxw9KXKKOn7D1FZNsaiT.g2Rdl/4V6qbkulOjUqi', // administrator
],
];

```
It's allready obvious that we need to change DB_NAME from atk-skeleton to our database wich is called 'conference', but what about the funny line ADMIN_PASSWORD?
It's allready obvious that we need to change db, user and password from 'atk-skeleton'/'root'/'' to our database parameters ('conference'/'conference'/'conference'), but what about the funny line ADMIN_PASSWORD?
The admin password is the administrative ATK password, when you login into an ATK application with the user **administrator**, all security is bypassed and you can do anything. It is the super user password.
You have to set an administrative password in the **.env** file, but you have to store it encrypted, ATK provides a tool to encrypt the password, and you invoke it like this:

` php ./vendor/sintattica/atk/src/Utils/generatehash.php demo`

The clear password is **demo**, once you run the command you'll get:
The clear password is **demo**, once you run the command you'll get something like:

```
clean: demo
hash: $2y$10$HURwCzn3JJmSV.8UZEVW/eaO/RSlYKELKFacIwTyKSPssxp101XDC
```

Let's edit our .env file, to look like this:
Let's edit our parameters.dev.php file, to look like this:

```
DB_NAME=conference
DB_USER=conference
DB_PASSWORD=conference
DEBUG_LEVEL=1

# adminpwd
ADMIN_PASSWORD="$2y$10$HURwCzn3JJmSV.8UZEVW/eaO/RSlYKELKFacIwTyKSPssxp101XDC"
<?php

return [
'atk' => [

'identifier' => 'atk-skeleton-dev',

'db' => [
'default' => [
'host' => 'localhost',
'db' => 'root',
'user' => 'conference',
'password' => 'conference',
'charset' => 'utf8',
'driver' => 'MySqli',
],
],

'debug' => 1,
'meta_caching' => false,
'auth_ignorepasswordmatch' => false,
'administratorpassword' => '$2y$10$HURwCzn3JJmSV.8UZEVW/eaO/RSlYKELKFacIwTyKSPssxp101XDC', // demo
],
];
```

But now that we specified the configuration in parameters.dev.php, how will the server know which parameters file to pick up ? The application will look up to an *environmental variable* called **APP_ENV**. The most simple way to set it is on the command line.

Ok, our basic configuration is done, now we can have a little gratification, let's
take a look to our app, in order to do so, let's start our personal php web server with:

`php -S 0.0.0.0:8000 -t web/`
`APP_ENV=dev php -S 0.0.0.0:8000 -t web/`

Now open your browser and navigate to **http://localhost:8000** you should see a login form. You can now login with user **administrator** and password **demo**.
Most probably, the login form is shown in the italian language (As the Sintattica.it are italians that should come as not surprising), let's tell our app to show up in good old english, edit de **config/atk.php** file and change the line:
Expand Down