Home » , » Yii 2.0.3 Updated with Fabulous Features

Yii 2.0.3 Updated with Fabulous Features

jaki watson | 21:48 | 0 comments
Yii Framework Development Services
Yii is one of the best open source web application development frameworks, used for every project type. Written in php5, developers are using this framework for developing robust web 2.0 applications. When comparing with other PHP-based framework, Yii delivers high-performing outcomes that drew positive attention towards viewers and developers.

Yii is best for high performing web applications such as social media sites, portals, forums and so on. Now, its come with latest update Yii 2.0.3, which comes with 50+ minor new features and bug fixes. If you are looking for a complete list of changes, then you can explore in the changelog. Yii also thanks to all its contributors, who have help them to enhance Yii and made this release possible.

Yii is also thankful to those contributors, who are improving documentation and translating into different languages. You may follow development progress of Yii 2 by watching and starring Yii2.0 GitHub Project. Even, twitterfeeds or Yii Facebook group joining is also possible by connecting with other Yii developers.

Here, we are going to mention some essential features that available along with this release.

Crypto Library Change

Internally, it is considered as a big change. Here, we have replaced Mcrypt with OpenSSL in yii\base\Security. All thanks to Tom Worster, who have helped to maintain high security standard for Yii, One shouldn’t have to experience any backward-compatibility issue as OpenSSL is developed into PHP by default. However, if you are doing then let us know.

RBAC Caching

Sometimes, one cannot find database’s performance ideal as developers are using it for storing RBAC data as each access check would contains the execution of different SQL statements.

Now, a caching mechanism is executed for yii\rbac\DbManager to enhance the performance. The whole RBAC hierarchy is stored by it in cache and thus, enhancement of the performance of checkAccess() is done. RBAC caching is not allowed by default. One may enable by configuring yii\rbac\DbManager in the application configuration, like:

return [
'components' => [
'authManager' => [
'class' => 'yii\rbac\DbManager',
'cache' => 'cache', // this enables RBAC caching
],
'cache' => [
'class' => 'yii\caching\ApcCache',
]
// ...
],
]

Page Caching

Earlier, page caching means to cache HTML content only. When you are attempting to cache RESTful responses, you will find it won’t work because of incorrect response format. One can use yii\filters\PageCache with the enhancement introduced in this release to cache different kinds of response data and response headers.

For example: One can easily cache an index action as given below:

public function behaviors()
{
return [
[
'class' => 'yii\filters\PageCache',
'only' => ['index'],
'duration' => 60,
],
];
}

Cache Busting for Assets

The support for cache busting of published assets is another enhancement related with caching. Usually, it can be seen in production servers that enable HTTP caching for CSS and JS files.

The disadvantage is that you make changes to these files. However, you may still use the old version because of HTTP caching. Now, one configure yii\web\AssetManager::appendTimestamp for enabling cache busting of published CSS and JS files.

The file modification time of the corresponding JS or CSS file will be added to each JS/CSS URL by setting this property to be true. Thus, whenever the file is changes, client will get latest version: 


return [
'components' => [
'assetManager' => [
'class' => 'yii\web\AssetManager',
'appendTimestamp' => true,
],
// ...
],
]

Changing Current URL

One can find a new helper method yii\helpers\Url::current() for easy modification of currently requested URL by removing or adding some GET parameters. Like:

// assume $_GET = ['id' => 123, 'src' => 'google'], current route is "post/view"
// /index.php?r=post/view&id=123&src=google
echo Url::current();
// /index.php?r=post/view&id=123
echo Url::current(['src' => null]);
// /index.php?r=post/view&id=100&src=google
echo Url::current(['id' => 100]);

Hindering Log Rotation

One can easily disable the automatic log rotation with a single property configuration by using yii\log\FileTarget. It is mainly useful when someone uses external tools for rotating log files.

return [
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'enableRotation' => false,
],
],
],
],
];

Data Attributes

The data attribute is specially handled when someone using yii\helpers\Html to generate HTML tags.

// displays: <div data-name="xyz" data-age="20"></div>
echo Html::tag('div', '', ['data' => ['name' => 'xyz', 'age' => 20]]);

In this way, one can also handled the ng attribute and data-ng attributes, which is mainly useful when we are working with AngularJS. An array will be turned into JSON format for all other attributes when it being embedded into an HTML tag.

Moreover, one can easily customize which attributes should be managed as shown by changing the yii\helpers\Html::$dataAttributes variable.

Trimming Input

One can find trimming is done on the client side as well if we are using trim validation rule. Such can be done in case a text input is connected with a trim validation rule. Moreover, the surrounding blanks will be trimmed automatically in the input data upon the input losing focus.

One can also set the enableClientValidation option of the trim, if they don’t like this new behavior. 


Max Length of Input

If you want to specify the maxlength attribute of the generated text input, you have to create a text input by using yii\helpers\Html::activeTextInput() or yii\widgets\ActiveField::textInput().

When we find a string validation rule connected with the corresponding model attribute, we may avoid clearly particular the value of maxlength as it already specified in the string rule. One can easily get this goal by setting maxlength and will be automatically populated with the value of the max option of the string rule. Like:

// assume "name" has a validation rule: ['name', 'string', 'max' => 128]
// generates: <input type="text" ... maxlength="128">
echo Html::activeTextInput($model, 'name', ['maxlength' => true]);

Configurable Objects

yii\base\Configurable, a new interface can be utilized to declare a class as configurable. The class constructor's last parameter will be assumed by the yii\di\Container that accepts a configuration array when a class implements this interface. Like:

class Foo implements \yii\base\Configurable
{
public function __construct($a, $b, $config = [])
{
}
}

$container = new \yii\di\Container;
$object = $container->get('Foo', [1, 2], ['prop1' => 3]);
// equivalent to: $object = new Foo(1, 2, ['prop1' => 3]);

One can have to encompass from yii\base\Object in order for a class to be treated before this release. If you want to update this release in your site/blog then hire Yii developers from Perception System, a leading web development company.
Share this article :

0 comments:

Post a Comment

 
Design by: