Yii 1.1: ewebbrowser

Detect user’s browser type and version
16 followers

This is a ported Yii version of the great Browser class made by Chris SChuld.

There are already some extensions for this class here, but they are wrappers and this is a full Yii CComponent class. I wanted to use it Yii style and also even provide an event on browser discovery.

I have created a GitHub repository for those willing to contribute on any of the extensions I created. Please, check the link at the bottom of this wiki.

Usage

How to use this extension is quite simple, check the code below:

$b = new EWebBrowser();
 
echo '__toString<br>';
echo $b;
 
echo '<p></p>';
echo '<h3>Testing properties now</h3>';
echo 'user agent: '.$b->userAgent.'<br>';
echo 'platform: '.$b->platform.'<br>';
echo 'version: '.$b->version .'<br>';
echo 'browser: '.$b->browser.'<br>';
echo 'is Chrome? '.($b->browser == EWebBrowser::BROWSER_CHROME?'YES':'NO');

If you wish to rather use an event approach, do the following (assuming you have a class with static method 'discover'):

// the class handling the browser discovery
class ETest {
    //put your code here
    public static function discover($event)
    {
                // check all properties of EWebBrowserEvent
                echo $event->browser_name. '<br/>';
                echo $event->agent. '<br/>';
                echo $event->version . '<br/>';
                echo $event->platform . '<br/>';
                echo $event->os . '<br/>';
    }
}
 
// now on creation it will call the static method above
$b = new EWebBrowser(null, array('ETest','discover'));

Resources

Total 5 comments

#5477 report it
Pomstiborius at 2011/10/15 03:51am
Sorry

Good to know, apparently somehow i skipped paragraph about extension and moved directly to the code. My bad, thanks for the info. :) In my next project i will try your extension and see which one is better.

#5474 report it
Antonio Ramirez at 2011/10/14 04:08pm
@pomstiborius

Is not a duplicate... the other one is a wrapper, this one is a component by itself.

"Browser is a simple wraper for the Browser Class, which is included." -from its text.

It is none better than the other one... is up to you to use this one or the other. In the usage I explained why I did a component instead of using a wrapper.

#5470 report it
Pomstiborius at 2011/10/14 11:34am
Duplicate?

How is this extension better than this one: http://www.yiiframework.com/extension/browser?

#5464 report it
Antonio Ramirez at 2011/10/14 03:59am
@yiqing95

Of course! You can change it, even use private variables if you feel like. :)

#5460 report it
yiqing95 at 2011/10/13 11:10pm
great extension , it 's useful for developing multi platform programs

CAttributeCollection class rarely be used ! nice example for using this class , is it ok if change it to stdClass ?

Leave a comment

Please to leave your comment.

Create extension