Various Yii 3.0 related documentation
If you haven’t used Yii2, you can skip this section and get directly to “getting started” section.
While sharing some common ideas and values, Yii 3 is conceptually different from Yii 2. There is no easy upgrade path, so first check maintenance policy and end of life dates for Yii 2 and consider starting new projects on Yii 3 while keeping existing ones on Yii 2.
Yii3 requires PHP 8.0 or above. As a result, there are language features used that weren’t used in Yii 2:
It’s a good idea to refactor your Yii 2 project before porting it to Yii 3. That would both make porting easier and benefit the project in question while it’s not moved to Yii 3 yet.
Since Yii 3 is forcing you to inject dependencies, it’s a good idea to prepare and switch from using
service locator (Yii::$app->
) to DI container.
If usage of DI container is problematic for whatever reason, consider moving all calls to Yii::$app->
to controller
actions and widgets and passing dependencies manually from a controller to what needs them.
See Dependency injection and container for an explanation of the idea.
Since Active Record isn’t the only way to work with a database in Yii 3, consider introducing repositories that would hide details of getting data and gather them in a single place you can later re-do:
class PostRepository
{
public function getArchive()
{
// ...
}
public function getTop10ForFrontPage()
{
// ...
}
}
In case you have a rich complicated domain, it’s a good idea to separate it from infrastructure provided by framework that’s all the business logic has to go to framework-independent classes.
Yii 3 services are conceptually similar to Yii 2 components, so it’s a good idea to move reusable parts of your application into components.