Menu
  • HOME
  • TAGS

Yii2, set default value for select2 widget

yii2,yii-widgets

When you update the model, it will automatically have the last selected value. $myModel = new \app\models\myModel; $myModel->attributes = \Yii::$app->request->post('myModel'); ...

Yii Framework Undefined Offset: 0

php,mysql,yii,yii-widgets

You need to set the mapping for sorting. /* Query results array( array( 'id' => 1, 'username' => 'username', 'email' => 'email' ), ... ) */ return new CSqlDataProvider($query, array( 'keyField' => 'id', //required, any field from query results 'totalItemCount'=> $count, 'pagination' => array( 'pageSize' => 10 ), 'sort' =>...

Yii widget reload via ajax

php,ajax,yii,yii-widgets

Here a small example. I hope this help you. Widget which show time from server every second. //SiteController public function actionTest() { $this->render('my_view'); //just rendering view } public function actionContent() { $this->widget('time'); //return html of widget. use for ajax } //my_view.php <script src="<?php echo $this->assetsBase ?>/js/jquery-1.10.2.js"></script> <script type="text/javascript"> $(document).ready(function() {...

YII widget access model - I need a value from DB in my layout

php,yii,yii-widgets

Yes, it is ok to create a widget for this needs. After done, it is ok to call it from layout. You can even use caching in order not to bother DB too often. http://www.yiiframework.com/wiki/17/how-to-make-use-of-a-fragment-cache/ Finally: I would recommend writing widget and using it with fragmental caching....

yii2 button with link

php,yii,yii2,yii-widgets

You could simply use Html::a() : <?= Html::a('label', ['/controller/action'], ['class'=>'btn btn-primary']) ?> Or create your own version of Button class to handle this. PS: you don't need Url::toRoute...

How to put default value in CJuidatepicker in Yii?

jquery-ui,yii,jquery-ui-datepicker,zii-widgets,yii-widgets

You can use Html value attribute for this <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array( 'name' => 'publish_date', 'attribute' => 'publish_date', 'model'=>$model, 'options'=> array( 'dateFormat' =>'yy-mm-dd', 'defaultDate' => '2014-3-4', 'altFormat' =>'yy-mm-dd', 'changeMonth' => true, 'changeYear' => true, 'appendText' => 'yyyy-mm-dd', ), 'htmlOptions'=>array('value'=>'2013-4-4') )); ...

uncaught exception: [CKEDITOR.resourceManager.load] Resource name “default” was not found

php,ckeditor,yii2,yii-widgets

There was problem with asset registration. I Kdiff current asset directory with another projects asset directory. And there was files missing I copied them in current project and now its running fine.

YII2 add horizontal scrollbar in gridview

gridview,yii2,horizontal-scrolling,yii-widgets

You just need to put a div around it and then set the overflow using CSS. You will need to set the height. overflow: auto; overflow-y: hidden; Height:? ...

Delete operation in CGridView in yii.

php,yii,yii-widgets

redirect to admin action Yii::app()->db->createCommand($query)->execute(); $this->redirect(array('admin')) ...

Yii2, what the model parameter does in widget?

yii2,yii-widgets

Select2 widget is an instance of Yii2 Input widget and it renders input for model attribute. It is useful for forms where you create/update your model. So e.g. if it is for actionCreate() you should use your new ActiveRecord model instance for widget 'model' attribute and any attribute name you...

Yii CGridView. Show columns from not related tables

php,yii,yii-widgets

You should try to use a radioButtonList and specify that the column is of a raw type: 'columns'=>array( ... //other columns array( 'name'=> 'test', 'type'=>'raw', 'value' => 'CHtml::radioButtonList("test", $select,array("key" => "value"), array("template" => "{input}", "separator"=>" "))', ), ), ), If you don't know how to use a radioButtonList you should...

Is it possible to render a view to a rendered page from the controller using Yii?

php,yii,yii-widgets

You said "previously rendered file" which I interpret that you have the main file already in view in the browser, and then you would like to have new data processed by the controller and passed back the view, for which you would need an ajax call from the main view...

YII2 add colspan in gridview header

gridview,yii2,yii-widgets

This is not possible without extending and rewriting the grid view widget. Take a look at Kartik GridView. If you take a look at the demo you can see that it has the functionality you need.