So, if you're anything like me, a busy independent developer, research and training projects always get pushed down to the bottom of that oh-so long list of things to do!
So this is the start of a series of posts introducing Yii2 and helping you to get up to speed as quickly as possible.
I will also be publishing a subscription tutorial series (a little like my Beginning Yii video series available from Packt). I haven't decided how to implement this yet but you can sign-up to my newsletter to be kept informed of progress. It will probably be an on-going publication that grows over time … so watch this space.
The first thing that strikes you about Yii2 is probably PHP5.4 syntax, names spaces and use statements. So let's start at the beginning …
Yii2 is dependent on PHP 5.4, so if you may well need to upgrade your webserver before you even start on Yii2. I'm using WAMPSERVER on Windows 8 and did this towards the end of 2013 before PHP 5.4 was available as a standard install, so it took me almost a day to get this working.
However, I just re-installed everything and WAMPServer comes as standard now with PHP5.4 so it should be easy.
Yii2 is also based on Composer so you will need to install this and get it running. I still have a few gremlins in my windows install, so I just donwloaded the Yii2 zip file and decompressed it into my webserver root directory.
For those of you who have followed my 'Beginning Yii' video course, you will remember that I make heavy use of virtual servers and thus can install each web project into it's own directory system.
Yii2 provides a couple of example apps, Basic and Advanced. I would strongly suggest that you start with the Basic app, even if you're reasonably experienced with Yii-1.x until you get familiar with namespaces and the various use libraries …
OK, have you looked at the all new PHP yet. If not, before you go any further, spend half an hour getting familiar with the latest features of PHP. rather than covering it here, there are loads of resources already on the net. I found this one by King Foo particularly good .
Let's get started
So now that you're familiar with PHP5.4 and namespaces – the first thing you'll notice when you up the Basic sample app, is that most of the files start with namespace appcontrollers;
So the Basic app only has one namespace, so for now, we just have to remember to put that at the top of every controller and every model.
The next big difference you'notice is a load of use statements. Now, I don't fully understand why we have to use these. I thought that Yii used an auto-loader and thus could find any of the classes that you reference. But apparently not. You have to specify what classes you want to use in every model, controller and view.
OK, so what else is new
Well, everything really … in part 2 we'll start looking at a summary of the changes