News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPMaster.com:
Under the Hood of Yii's Component Architecture, Part 3
February 14, 2012 @ 09:28:34

PHPMaster.com is back with the third part of their series looking at the internals of the Yii framework (specifically, its components). In this latest article Steven O'Brien focuses on how the framework uses behaviors.

A behavior, as it is called in Yii, is a manner of combining objects at runtime to extend an object's functionality. Behaviors are an excellent way to decouple code and keep ever expanding systems maintainable. [...] We can not reuse our code effectively because PHP doesn't support multiple inheritance. The Yii behavior system is a way of achieving multiple inheritance by implementing mixins.

He gives an example of working with a user that's connecting to your application just to get to a third-party billing system. They show how to take this functionality our of your generic "User" class and make a behavior out of it. This functionality can then be attached to the User object (via an attachBehavior call) and used directly. He gets into how Yii does this magic, showing how it appends it to a special value in the class and the __call method checks the method call to see if it exists in one of these special classes.

0 comments voice your opinion now!
yii component tutorial component behavior mixin


blog comments powered by Disqus

Similar Posts

David Coallier's Blog: Namespaces has PHP 5.3 (Or the other way around)

Sameer Borate: Debugging Laravel with MonoLog and FirePHP

Freeaqingme's Blog: PHP, JS & Service layers: Blend like never before

User Group: Boston PHP Welcomes Chris Shiflett

Zend Developer Zone: Indexing Email Messages with PHP, Zend Lucene and Sphinx


Community Events

Don't see your event here?
Let us know!


laravel introduction performance release application conference php7 language opinion podcast interview framework example voicesoftheelephpant community series api symfony2 part2 configure

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework