I'm sure you have some third-party PHP software that you'd like to run in a Yii view but you don't know how to do it. I have the solution! For example, I'm running the PHP free chat in a view --> http://yiimarket.ho96.com/phpfreechat. How I achieved that? Well, I created a very simple extension, in which I put an iframe, and I resized it via jquery.
namespace ho96\phpfreechat; use Yii; use yii\web\View; use yii\base\Widget; class PHPFreeChat extends Widget { private $_assetsUrl; public function run() { if($this->_assetsUrl === null) { $assets = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets'; $this -> _assetsUrl = Yii::$app->getAssetManager()->publish($assets, array('beforeCopy' => function($from, $to) { if(strpos($from, '.directory') < 1) return $from; } )); } $this->getView()->registerJs(" resizeIframe(); $(window).resize(function(){ resizeIframe(); }); function resizeIframe() { $('iframe').attr('width',$('#iframe-div').width()); $('iframe').attr('height','770'); } ", View::POS_END, 'iframe'); echo '<div id="iframe-div">'; echo '<iframe src="' . $this->_assetsUrl[1] . '/phpfreechat"></iframe>'; echo '</div>'; } }
You can download the extension here: http://www.yiiframework.com/extension/yii2-phpfreechat
This article may seem a little bit silly, but I considered that I could be useful, so I wrote it.