Web Application Development with Yii 2 and PHP

September 24, 2014

Holy cow, I wrote a book!

After the terror of 6 months writing, re-reading and re-writing, “Web Application Development with Yii 2 and PHP” have finally been published at 26th of September.

It was completely unexpected for me to receive this contract, I have never used version 2 of Yii framework, which was in early beta at the time, and had quite small Web presence to be spotted by any publisher. But it happened (thank you, God).

Yeah, URL is, and, honestly, without any self-promotion, if you want to develop using Yii 2, go buy this book, because I took a lot of time inspecting this framework so you will not need to do the same. For example, you will not get the exact details of how the error reporting works in Yii from the official documentation. The code is always the last source of truth, and I tried hard to express in plain technical English what it actually does.

To be honest, I strongly dislike Yii. I think that Yii 2 is enormous leap forward since version 1.1.x but I still dislike this framework. Each book I read about pro-level software development tells me things which I find completely ignored or misinterpreted in Yii. Reading its code was also not a pleasurable experience.

And trust me, our team at Clevertech is maintaining a ~80KLOC application based on Yii 1.1 idioms (initially) and at second year we came to conclusion that we don’t need most of it. For example the whole ActiveRecord layer. I don’t even talk about basing the project structure on the conventions, “models-controllers-views” directory triad is a biggest bullshit I saw so far in my career. Our “common/models” directory has like 15 subfolders in it, and we have no other choice, because you cannot stuff everything into ActiveRecord descendant, and there’s no “domain_models” directory in the bastard of MVC which Yii implements.

Err… I went away. The book. Right.

I wrote it nevertheless. I am working with Yii application (version 1.1 though) every day and actually can tell a thing or two about it. So, publisher asked and I answered.

I had two main premises when writing.

  1. Show how you can use Yii 2 when developing your application, not simply “how to use Yii 2”, which is covered already by official documentation.
  2. Show how to work in ATDD manner with CI in mind, even using the framework. There is clearly not enough literature which shows how to properly develop applications right from the start, without rudimentary examples like bowling kata.

So, the whole Chapter 2 is a glorious implementation of the point 2. Or so I thought. This chapter ended being probably of the worst quality from the whole book. It contains so much testing harness and deployment machine setup that in the end I separated the whole Appendix out of it and had thrown away around 10 pages which were not related to Yii 2 at all. And it  may be still so boring to read (if you wanted to learn Yii 2 and know that stuff already) that probably 9/10 readers will drop the book right there and not go to the really interesting stuff like how Yii 2 extensions work or its event system or new Request/Response model.

The book uses a single example application, slowly adding more and more features from chapter to chapter. The application is pretty trivial, it’s a CRM skeleton, and by the end of the book there are mainly two features: adding the customer and fetching his info given the phone number; and sign in to the system using login/password. There are also a whole Yii 2 extension, though.

I seriously tried to put all I learned through the professional literature like the DDD, GOOS, Clean Code and such, but I personally think I failed at this quite spectacularly. :) But apart from that, I tried my best to show the pieces of the Yii 2 picture which are not covered (and probably will never be) by the official docs and references. Hope it’ll be useful for you.

Also, there’s no other book on this topic yet so you have no choice anyway. ;)

There were a serious misunderstanding from my part also: I completely missed the point that this book is legally the “second edition” of the previous book, “Web Application Development with Yii and PHP” (note the absence of the number 2) by different author, Jeffrey Winesett. The outcome of this is that I become something like a co-author with both names present on the cover. It hurt a bit, as I lived 6 months in permanent crunch mode (book writing is not my fulltime job after all) and Jeff is not related to this book at all, but we both are listed as authors equally. This does not apply to the royalties, though, so I am not bothered by this so much.

I did this for greed, not for pride, after all. :) This is not the kind of book I would be proud of. Personally, I would promote Common Lisp-based development, not the Yii 2 framework (doh) over PHP (holy cow).

Previous: The Vis Major book Next: Russian Translation of Web Application Development with Yii 2