Home » , » Yii 2.0 Release Candidate Is Released

Yii 2.0 Release Candidate Is Released

jaki watson | 23:38 | 0 comments

Yii Framework Development
Good news for Yii users as the Yii 2.0 RC (Release Candidate) is released and one can follow the instruction on yiiframework.com for installing and upgrading to the latest version. About 100 bug fixes and 200 new features and enhancements are included in this RC release, which is considered as one of the biggest releases.

Let’s check out some important features that come with this latest release. Before that, you must read the Definitive Guide to know what exactly Yii 2.0 is. In this release, a complete list of changes can be available in CHANGELOG.

Security

Here, we have added the previous Security helper class into the security application component in order to support customization of some security features. Now, users can easily access security-related features via expressions like Yii::$app->security->encrypt(). Apart from, many minor changes are also done that enhance the security issues.

Like: CSRF tokens can be stored in sessions instead of cookies if you set yii\web\Request::enableCsrfCookie to be false; httpOnly is now turned on for all cookies by default and so on.

Database

Database Replication and Read-Write Splitting

Now, one can find built-in support for read-write splitting and database replication. Database replication allows replicating from the master servers to slave servers. All the updates and writes must take place on the master servers and reads may take place on the slave servers. If you want to configure your DB connection to use this feature then follow below given coding:

[
'class' => 'yii\db\Connection',
// configuration for the master
'dsn' => 'dsn for master server',
'username' => 'master',
'password' => '',
// common configuration for slaves
'slaveConfig' => [
'username' => 'slave',
'password' => '',
],
// list of slave configurations
'slaves' => [
['dsn' => 'dsn for slave server 1'],
['dsn' => 'dsn for slave server 2'],
['dsn' => 'dsn for slave server 3'],
],
]

One can simply continue writing DB query code with this configuration. Moreover, the slaves will be used automatically to conduct the query if it is fetching data from database. The master will be used if the query is updating or inserting data into database.

Transactions

Using DB transactions come with many enhancements. First of all, you have to work with transactions in a callback style like:

$connection->transaction(function() {
$order = new Order($customer);
$order->save();
$order->addItems($items);
});
This is equivalent to the following lengthy code:

$transaction = $connection->beginTransaction();
try {
$order = new Order($customer);
$order->save();
$order->addItems($items);
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollBack();
throw $e;
}

Secondly, a few events are activated for transactions. Lastly, you have to set transaction isolation levels (e.g. READ COMMITTED) at the time of beginning with new transaction.
$transaction = $connection->beginTransaction(Transaction::READ_COMMITTED);

Building Query Conditions

Use arbitrary operators for developing a query condition. The operator >= is used in the given example for building a query condition age >= 30. Moreover, Yii will be quote the column name and use parameter binding for handling the value.

$query = new \yii\db\Query;
$query->where(['>=', 'age', 30]);
You can use sub-queries when creating an in or not condition.
$subquery = (new \yii\db\Query)
->select('id')
->from('user')
->where(['>=', 'age', 30]);
// fetch orders that are placed by customers who are older than 30
$orders = (new \yii\db\Query)
->from('order')
->where(['in', 'customer_id', $subquery])
->all();

Want to know more about this latest release, please visit check this link. If you want to learn more about new syntaxes, go through the Definitive Guide.

More Information Regarding Yii Framework Development Services Click here.
Share this article :

0 comments:

Post a Comment

 
Design by: