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'));
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 ?
@yiqing95
Of course! You can change it, even use private variables if you feel like. :)
Duplicate?
How is this extension better than this one: http://www.yiiframework.com/extension/browser?
@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.
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.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.