Home » , » Yii Framework Introduces Yii 2.0 Beta Version

Yii Framework Introduces Yii 2.0 Beta Version

jaki watson | 03:41 | 0 comments

Yii Framework 2.0 Beta Version
The Beta release of Yii Framework version 2 is announced by the officials. Now, you can download it from yiiframework.com. This latest version comes with changes and bug fixes, hundreds of new features, and many other things. Continue reading post for more detailed information.

Structure

The PSR-4 standard is followed by Yii 2 for its class autoloading. This results in three improvements, i.e.

  • Simpler extensions directory structure.

  • Simpler framework directory structure.

  • We've dropped PEAR-style class naming resulting in simpler and faster autoloading.

Now, controller classes required to be namespaced and must be situated under Module::controllerNamespace, unless you use controller mapping via Module::controllerMap. Back the support has been added by us for grouping controllers by subdirectories, which is also supported in 1.1.

Usability

One of the highest priorities for the Yii team is usability and thus, we are spending enough time for selecting good names for everything, creating code work with IDEs better resulting in more enjoyable daily development experience. PSR-1 and PSR-2 are also adopted by us and received excellent support from code style checkers, various IDEs, and automatic formatters.

Performance

An important change we have seen in this version is it is not started until it actually used. It results into application that doesn’t waste resources on starting sessions unnecessarily. Users may find an improved the MarkDown formatting speed, if he/she is using MarkDown in their project. This is because Carsten Brandt (cebe) created a new MarkDown library from scratch after examining all existing solutions. The latest library is much faster and is easier to be extended. GitHub flavored format and many other features are supported by it.

Security

Now, masked CSRF tokens are used by Yii to prevent BREACH type of exploits. RBAC biz rules were refactored that result in to more flexible yet safer solution. The use of eval() for biz rules are also eliminated.

RESTful API framework

This latest version comes with built-in support for RESTful API development. If you want to know more about this version, then look at below given supported features:
  • Customizable object serialization with support for selectable output fields;

  • Support for OPTIONS and HEAD verbs;

  • Proper formatting of collection data and validation errors;

  • Quick prototyping with support for common APIs for ActiveRecord;

  • Response format negotiation (supporting JSON and XML by default);

  • Efficient routing with proper HTTP verb check;

  • Authentication;

  • Authorization;

  • Support for HATEOAS;

  • HTTP Caching;

  • Rate limiting.

Model Validation

Many useful enhancements are available to the model validation. Now, the UniqueValidator and ExistValidator are supported by validating multiple columns. 

Some of the examples are:

// a1 needs to be unique
['a1', 'unique']
// a1 needs to be unique, but column a2 will be used to check the uniqueness of the a1 value
['a1', 'unique', 'targetAttribute' => 'a2']
// a1 and a2 need to be unique together, and they both will receive an error message
[['a1', 'a2'], 'unique', 'targetAttribute' => ['a1', 'a2']]
// a1 and a2 need to unique together, only a1 will receive the error message
['a1', 'unique', 'targetAttribute' => ['a1', 'a2']]
// a1 needs to be unique by checking the uniqueness of both a2 and a3 (using a1 value)
['a1', 'unique', 'targetAttribute' => ['a2', 'a1' => 'a3']]
One can simply do validations conditionally. The addition of two properties supports this when and whenClient to each validator. With this example, you can see ‘how to require the "state" input only when the country is selected as "USA"’:
['state', 'required',
'when' => function ($model) {
return $model->country == Country::USA;
},
'whenClient' => "function (attribute, value) {
return $('#country').value == 'USA';
}",
]
Many a time, you have to do some ad-hoc data validation without the trouble of writing new model classes. In such situation, you can the new yii\base\DynamicModel to accomplish this new model classes. For example,
public function actionSearch($name, $email)
{
$model = DynamicModel::validateData(compact('name', 'email'), [
[['name', 'email'], 'string', 'max' => 128],
['email', 'email'],
]);
if ($model->hasErrors()) {
// validation fails
} else {
// validation succeeds
}
}

In addition to this, you can have some more features in this latest version. This Beta release has involved tremendous efforts from all the leading parties. If you want to know some more information in details, then click here. If you are thinking to adopt Yii Framework Development Services for your project requirements, hire Yii web developers from Perception System.
Share this article :

0 comments:

Post a Comment

 
Design by: