Yii3 - How to start

Comparing #61 with #62

Revision #62 was created by rackycz rackycz on Aug 30, 2026, 8:23:58 AM.

update

Content

Don't forget to like and subscribe :-)
 
 
# Intro

In Yii3 it is not as easy to start as it was with Yii2. You have to install and configure basic things on your own. Yii3 uses the modern approach based on independent packages and dependency injection, but it makes it harder for newcomers. I am here to show all how I did it.
[...]
All my code is available in my GitHub repositories:
- [Yii3 API demo](https://github.com/rackycz/yii3api) (yii3api) - May be dropped in the future as `yii3web` offers more)
 
- [Yii3 WEB demo](https://github.com/rackycz/yii3web) (yii3web) - I think I will use this one more

I will be using it as a boiler-plate for my future projects so it should be always up-to-date and working.
[...]
## PSR Standards by Framework Interoperability Group
First of all, learn what [PHP Standards Recommendations](https://en.wikipedia.org/wiki/PHP_Standard_Recommendation) by [Framework Interoperability Group (FIG)](https://www.php-fig.org/psr) are. It will help you understand why so many "weird" PSR imports are in the Yii3 code.
 
 
 
In short: These interfaces help authors of different frameworks to write compatible classes so they can be reused in any other framework following these principles(if the framework also uses PSR).

## Dependency injection + container
[...]
The Yii team split the functionalities if Yii3 into 135 packages which you should check in advance to know what is available. They are listed [here](https://www.yiiframework.com/status/3.0) or the same is also [here](https://www.yiiframework.com/doc/api/3.0).

For example [login](https://github.com/yiisoft/user) and [RBAC](https://github.com/yiisoft/rbac), which can be stored in [DB](https://github.com/yiisoft/rbac-db) or in [PHP files](https://github.com/yiisoft/rbac-php/). And many more like "active-record"
 (which is now finished), "form-model" or "boostrap5".

## invoke()
[...]
# Yii3 - How to start

Yii3 offers more basic applications: Web, Console, API. I will be using the
APIWEB application: - https://github.com/yiisoft/app-api - Other apps are linked on the page Clone it like this: - git clone https://github.com/yiisoft/app-api.git yii3apiweb

.. and follow the **docker** instructions in the documentation.
[...]
## Running the demo application

You may be surprised that docker-compose.yml is missing in the root. Instead the "make up"
, "make stop" and "make down" commands are prepared.
If you run both basic commands as mentioned in the documentation:
[...]
If you want to modify the data that was returned by the endpoint, just open the action-class `src/Api/IndexAction.php` and add one more element to the returned array.

> You may be missing 'docker compose stop' or 'make stop', because 'make down' removes your containers and drops your DB. In that case you can add it to the Makefile in the root (see below). If you then type 'make help' you will see the new command. 
 
 
```sh
 
ifeq ($(PRIMARY_GOAL),stop)
 
stop: ## Stop the dev environment
 
$(DOCKER_COMPOSE_DEV) stop
 
endif
 
```
 
 
## Disclaimer I am just learning Yii3. Its new architecture is not my cup of tea so I am trying my best to reach my goals. (I left world of Java+Spring because of these complex DI configurations and now it's back :-o ) If you find a better implementation, let me know. I am not an architect, but a real-life developer who solves daily problems in the world of bussiness and industry so sometimes I may produce too straightforward or philosophically imperfect solutions.

## Adding DB into your project
[...]
services:
app:
container_name: yii3
apiweb_php
build:
dockerfile: docker/Dockerfile
[...]
db:
image: mariadb:12.0.2-noble
container_name: yii3
apiweb_db
environment:
MARIADB_ROOT_PASSWORD: root
[...]
adminer:
image: adminer:latest
container_name: yii3
apiweb_adminer
environment:
ADMINER_DEFAULT_SERVER: db
[...]
Login, server and pwd is defined in the snippet above.

If you type "docker ps" into your host console, you should see 3 running containers: yii3
apiweb_php, yii3apiweb_adminer, yii3apiweb_db.

The web will be, from now on, available on URL http://localhost:9080 which is more handy than just ":80" I think. (Later you may run 4 different projects at the same time and all cannot run on port 80)
[...]
> - Now you are in the console of your php server and you can run composer.
>
> - If you are using PhpStorm, find the small icon "Services" in the left lower corner (looks ca like a cog wheel), find item "Docker-compose: app-api", inside click the "app" service, then "yii3
apiweb_php" container and then hit the button "terminal" on the righthand side.

### **Setting up composer packages**

Follow their documentations. Quick links:
- https://github.com/yiisoft/db/blob/master/docs/guide/en/connection/mysql.md (I did not need the snippet with "new DsnSocket()")
[...]