I’ve been using yii1 and yii2 since 2015. as day to day user and lover of this framework, and plus currently work on laravel codebases too.
It’s hard to talk about this V3 without talking about V2 and V1, cause everything we feel it’s relative to the previous versions and previous experiences with other codebases.
So lets me open this out for everyone to see:
What worked well for Yii1 and Yii2:
One truth that we can all agree on is: Yii1 it’s not a php modern approach in the code itself but it’s still modern on the way of thinking about a web application. It’s easy to code an api/web interface once you get familiar with. Recently i modernized some ui fragments using htmx + yii1 and it just works perfect with the standard renderPartial(even added a small trait function to allow rendering of multiple partials at the same request as htmx introduces nicely this pattern). This is empowering almost 10y maintaining and updating Yii based applications and never stepped on my shoe, never was a problem, never noticed a bug and never there was a point of debate of replacing Yii. That’s surely due to the quality of the PHP code produced on Yii on the past 10y and the hard working and validation on every line commited on both codebases, as a user of this framework i trust in every line of code produced by it.
What didn’t work well on (v1,v2):
The quality of extensions. As a Yii user i don’t want any kind of extensions on my apps cause it’s easy anyways to extend it with inheritance myself. Or even install a composer package that nicely solves what i want and port it nicely to Yii using a CComponent/Component in case of being a service or a standalone class/function that solves that particular problem to me.
It’s not a global truth but i feel Yii2 reached the fine spot where we actually don’t need any kind of extension to work with, so thats how i feel about it’s extension system didn’t catch up.
The documentation is awesome as a hard user, but as a newcomer it lacks real use cases examples.
I’ve been waiting to grab on my hands Yii3 for such a long time. I’m already asking for forgiveness for writing such a long text for first impression, but i think Yii deserves more than a 5 lines opinion.
First positive impressions
-
FormModel works nicely, i personally like the Model approach to adding business logic and validating it. What i personally like to write is something like: SignInForm extends …Yii default form class and implement it nicely to keep my controllers out of trouble. Also it’s much more testable to write it in a Model which it’s easier to test/find extend. The annotations(Java like) approach works great for those coming from .NET and Java like enviroment(PHP → Java, Java → PHP) always felt very familiar to me.
-
Folder structure, nothing to talk about didn’t change that much
-
Middleware patterns are very familiar nowadays, in short words, it’s a functional way to solve problems and allow extensibility. It always come with a price of every middleware having to lookup and take care to not break/slow the entire application but it’s so easy to plug-and-play that worth the cost.
-
Finally standarized responses as returns, that’s something that bothered me a bit on Yii2 and Yii1. Also for PHP 8 have this ResponseInterface as default on developing is just heaven. Also i don’t see a world beside command line controllers where responseFactory is not a default.
public function auth(ServerRequestInterface $request): ResponseInterface
{
$response = $this->responseFactory->createResponse(); <- A better way that it could be written is ResponseFactory::create(); i don't see a point of having as state of $this
$response->getBody()->write('Hi ' . $request->getAttribute('username')); <- love it
return $response;
}
-
Services being injected on constructors is something that we always hoped for but we already could make it on our own on Yii2 but seeing it as a standard, don’t need to think much to know that it will work. Btw i will miss the old Yii::$app->paymentSystem/Yii:app()->paymentSystem too, there is some value too to having it as a global singleton. Middleware pattern are a huge win and i don’t think someone will ever configure it globally to be honest…
public function __construct(
private ExtraDataStorage $extraDataStorage // Data storage is easy to test, and insert whenever i can. That's great
)
{
}
-
Packagist as default. We all know about it don’t need say anything to know it’s good to have it as default way to install things on our Yii3 apps.
-
Routing, Yii1/Yii2 didn’t have nice defaults for routing, yii1 is one camelCase, yii2 is a modern approach but it does not hide index.php as default so to be honest it never was a strong point on neither versions. Now it basically functions as laravel route.php where we can hard code it the way we want. We need that on Yii2 to be honest
. I consider solved for Yii3 and can sleep peacefully implementing rest urls without pain.
-
Migrations, not really differs that much from what we had to have an opinion about it
. And to be honest i didn’t write that much with it, i just hope that we had nice defaults like laravel blueprint for timestamps our to linking a table into another based on a relation:
just an example of what i mean:
Schema::create('flights', function (Blueprint $table) {
$table->id();
$table->timestamps(); // creates a created_at, updated_at that we often need on many tables...
});
-
ViewRenderer finally we have the html separated from the controller. I hope the viewRenderer could grow to suit every MPA need for rendering html to browsers: like having theme(light/dark mode) built in and allowing rendering multiple partials at once in a single call.
-
Widgets, not really changed. It feels like a Yii3 port of we had on Yii2.
First negative impressions
-
It’s nice to have everything nice and organized per domain but small businesses we value more the hability to change things fast and with a certain level of misture between concepts(concepts that we often do not understand the domain very well). That’s not only a problem for Yii but for this whole domain driven concept.
-
Security as default, that’s something that we miss on every Yii version. I would i want not to escape user input anyway? Should be the default to escape it. Every unsafe way to do things should be hidden by default to the developer. Instead of teaching on the docs how to secure a Yii application, should have how to disable these default guardrails.
-
I miss the basic template, why would someone that’s someone on my team needs to learn so much to get start building? Laravel has a better DX when it comes to getting started. That’s something critical that should be fixed on the docs on how to get this thing running in less than 5 minutes.
-
View injections, that’s a hard name for what we call on SPA applications to: Context. Whenever we need to pass properties we call prop and whenever we pass a huge amount of props and many views depend on it, we call it context. It’s far to hard to work with it, i can understand why the following example would not be something to be considered a better approach:
Somehere on the application struture core/context/ProfileContext.php
final class ProfileContext extends ViewRendererContext {
public function __construct(public readonly ...$props, // even some service) // thats pseudo code to not exhaustively write the possible props
}
inside the view.php or any layout:
if (!$this->context instanceof ProfileContext)
throw new Error('This view template requires ProfileContext');
... the rest of the html
- Often widgets on Yii1/2/3 requires css and js to be shipped alongside the reusable widget. I wish we had that. In that way when rendering partials or entire page renders we can control better when the js/css would be loaded. That would help us to not have to write entire global css/js files that do not be needed to be used on most of the screens.
abstract public class Widget {
public function registerAssets(): void;
}
There is some other considerations but the main ones are there.
Personally what i really think would help Yii3 adoption for current Yii1 and Yii2 users is mainly the creation of a micro framework that wires the Yii3 movable pieces on a opinated direction. I’m talking about having the config, assets, views, controllers, widgets. Having a WebController with all the things injected that we need for rendering html, ApiController for having the things that we need to develop smoothly an api. It still lacks good defaults.
It feels, don’t get me wrong, a framework to build a frameworks which it’s not.