Difference between #183 and #184 of
Yii v2 snippet guide

Revision #184 has been created by rackycz on Mar 21, 2020, 11:29:08 AM with the memo:

formatting
« previous (#183) next (#185) »

Changes

Title unchanged

Yii v2 snippet guide

Category unchanged

Tutorials

Yii version unchanged

2.0

Tags unchanged

tutorial,beginner,yii2

Content changed

[...]
When cloned, copy the content of the "basic" folder into the new empty git-folder and push everything except for folder "vendor". (It contains 75MB and 7000 files so you dont want to have it in GIT)

Then you can start to modify you project, for example based on this "tutorial".

. .
 

**Automatical copying from GitLab to FTP**
---
[...]
- exclude web/index-test.php = tests are only on your computer and in GIT

.
 
 
.
 
 
**User management + DB creation + login via DB**
---
To create DB with users, use following command. I recommend charset **utf8_unicode_ci** (or utf8mb4_unicode_ci) as it allows you to use [more international characters](https://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci).
[...]
```

.
 
 
.
 

**i18n translations**
---
[...]
Yii will automatically use the Czech version if needed.

.
 
 
.
 
 
**Switching languages + session + lang-dropdown in the top menu**
---
First lets add to file config/params.php attributes with list of supported languages:
[...]
As you can see in the snippet above, other controllers must contain row "use app\controllers\BaseController" + "extends BaseController"

.
 
 
.
 

**Simple access rights**
---
[...]
Details can be found here [https://www.yiiframework.com/doc/guide/2.0/en/security-authorization](https://www.yiiframework.com/doc/guide/2.0/en/security-authorization).

.
 
 
.
 
 
**Nice URLs**
---
Just uncomment section "urlManager" in config/web.php .. htaccess file is already included in the basic demo. In case of problems see [this link](https://stackoverflow.com/questions/26525320/enable-clean-url-in-yii2).
[...]
Note that **Yii::$app->request->baseUrl** returns "/myProject/web". No trailing slash.

.
 
 
.
 
 
**How to redirect web to subfolder /web**
---
Note: If you are using the advanced demo app, [this](https://stackoverflow.com/questions/37451324/how-to-change-base-url-and-enable-prettyurl-in-yii2) link can be interesting for you.
[...]
I will test this and if I find problems and solutions I will add them.

.
 
 
.
 
 
**Auto redirection from login to desired URL ** --- ... to be added ... .
 
 
.
 
 
**What to change when exporting to the Internet**
---
- Delete file web/index-test.php
[...]
- Delete the text from view site/login which says "You may login with admin/admin or demo/demo."

.
 
 
.
 
 
**Saving contact inqueries into DB**
---
```sql
[...]
```

.
 
 
.
 
 
**Tests - unit + opa** --- ... text ... .
 
 
.


**Adding a google-like calendar**
[...]
You can customize the calendar in many ways. For example different event-color is shown [here](https://fullcalendar.io/docs/event-colors-demo). Check the source code.

.
 
 
.
 
 
**Scenarios - UNKNOWN SCENARIO EXCEPTION**
---
I have been using scenarios a lot but today I spent 1 hour on a problem - I had 2 scenarios and one of them was just assigned to the model ...
[...]
... but had no **rule** defined yet. I wanted to implement the rule later, but I didnt know that when you set a scenario to your model it **must** be used in method rules() or defined in method scenarios(). So take this into consideration. I expected that when the scenario has no rules it will just be skipped or deleted.

.
 
 
.
 
 
**Richtext / wysiwyg HTML editor - Summernote**
---
If you want to allow user to enter html-formatted text, you need to use some HTML wysiwyg editor, because ordinary TextArea can only work with plain text. It seems to me that [Summernote](https://summernote.org/getting-started/#simple-example) is the simplest addon available:
[...]
... to discover all possible formatters, check all asXXX() functions on [this](https://www.yiiframework.com/doc/api/2.0/yii-i18n-formatter) page:

.
 
 
.
 
 
**SEO optimization**
---
This is not really a YII topic but as my article is some kind of a code-library I will paste it here as well.
[...]
You can also minify [here](https://www.willpeavy.com/tools/minifier/) or [here](http://minifycode.com/html-minifier/) all your files. Adding "microdata" can help as well, but I have never used it. On the other hand what I do is that I compress images using these two sites [tinyjpg.com](https://tinyjpg.com/) and [tinypng.com](https://tinypng.com/).

.
 
 
.
 
 
**Other useful links** --- - [SVG to CSS-background-image convertor](https://websemantics.uk/tools/svg-to-background-image-conversion/) .
 
 
.
 
 
**jQuery + draggable/droppable on mobile devices (Android)**
---
[...]
```

.
 
 
.
 
 
**Enhancing Gii**
---
If you do not like entering long model-paths and controller-paths in CRUD-generator, you can modify text boxes in "\vendor\yiisoft\yii2-gii\src\generators\crud\form.php" and enter default paths and then only manually add the name of the model.
[...]
```

.
 
 
.
 
 
**Webproject outsite docroot (htdocs) folder (Windows)**
---
If you need to store you project for example in folder D:\GIT\EmployerNr1\ProjectNr2, you can. Just modify 2 files and restart Apache (I am using XAMPP under Win):
[...]
You can then use http://myFictiveUrl.local in your browser

.
 
 
.
 
 
**Modal window + ajax**
---
Let's have a GridView (list of users) with edit-button which will open the edit-form in a modal window. Once user-detail is changed, ajax validation will be executed. If something is wrong, the field will be highlighted. If everything is OK and saved, modal window will be closed and the GridView will be updated.

Let's add the button to the GridView in the view **index.php** and let's wrap the GridView into the Pjax. Also ID is added to the GridView so it can be refreshed later via JS:
[...]
7 0
4 followers
Viewed: 254 692 times
Version: 2.0
Category: Tutorials
Written by: rackycz
Last updated by: rackycz
Created on: Sep 19, 2019
Last updated: 5 months ago
Update Article

Revisions

View all history