Okay, there were a lot of questions about moving to ‘unstable’ version 2.
I give you five things I like the most.
- Code styling standards.
As for me, the old code styling was awful. In fact, there was no style at all (sorry guys).
New code has strict coding standards similar to Zend (?). And tabs. I like tabs.
- Php 5.4.
Runs faster, good syntax, many enhancements (see changelog). Actually, they had me at short arrays
And no, it’s not a drawback, it’s the reason you must come to your boss (or hosting company) and say “hey, gimme 5.4!”
- User identity and RBAC.
Nothing to say here, these two had just become much simpler.
- asArray()
Take a look at this:
MyModel::find()
->scope1()
...
->scopeN()
->andWHere(['some_field' => 'some_value'])
->asArray()
->all();
So here I take my model, add some named scopes and other ActiveRecord (ActiveQuery actually) stuff, and then return all the records without constructing the AR objects. It saves memory, and also you can do something like…
- …response formatting.
You’ve probably noticed already that Yii2’s actions must return render result now.
And (besides other cool things) now you can do this:
$data = MyModel::find()
->asArray() // asks query to return array of data
->all();
\Yii::$app->response->format = 'json'; // how about xml?
return $data;
Isn’t it cool?
Moreover, response formats are extensible, so you can create your own, and then - boom! - response->format = ‘pdf’!
Well, there are many other things actually (like composer packages, new RAR, View class, et cetera et cetera) but you’ll definitely love these five.