PHP code example of petrgrishin / yii-widget-factory
1. Go to this page and download the library: Download petrgrishin/yii-widget-factory library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
petrgrishin / yii-widget-factory example snippets
use \PetrGrishin\WidgetFactory\WidgetFactory;
class CommentsModule extends CWebModule {
public function getCommentsWidgetFactory() {
if (empty($this->_commentsWidgetFactory)) {
$this->_commentsWidgetFactory = new WidgetFactory();
$this->_commentsWidgetFactory
->setClassName(Widgets\CommentsWidget::className())
->setParams(array(
'listUrl' => $this->createModuleUrlBuilder('comments/list'),
));
}
return $this->_commentsWidgetFactory;
}
}
class SiteController extends CController {
public function actionDetail() {
$this->render('detail', array(
'commentsWidgetFactory' => $this->getCommentsWidgetFactory(),
));
}
/**
* @return \PetrGrishin\WidgetFactory\WidgetFactory
*/
protected function getCommentsWidgetFactory() {
return $this->getCommentsModule()->getCommentsWidgetFactory()
->setView($this);
}
/**
* @return CommentsModule
*/
protected function getCommentsModule() {
return Yii::app()->getModule('comments');
}
}