yii2

Yii2 Gridview - How use totals on footer property

醉酒当歌 提交于 2019-12-20 10:58:21
问题 My VALUE column is: [ 'attribute' => 'value', 'format' => 'raw', 'contentOptions'=>['style'=>'width: 10%;text-align:left'], 'footer' => ??? ], How use totals of rows on FOOTER property ? 回答1: it's works 1. create class then 2.create column array, 3.configure column, 4.configure grid namespace app\components; class PTotal { public static function pageTotal($provider, $fieldName) { $total=0; foreach($provider as $item){ $total+=$item[$fieldName]; } return $total; } $provider = new

Yii2 Gridview - How use totals on footer property

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 10:58:16
问题 My VALUE column is: [ 'attribute' => 'value', 'format' => 'raw', 'contentOptions'=>['style'=>'width: 10%;text-align:left'], 'footer' => ??? ], How use totals of rows on FOOTER property ? 回答1: it's works 1. create class then 2.create column array, 3.configure column, 4.configure grid namespace app\components; class PTotal { public static function pageTotal($provider, $fieldName) { $total=0; foreach($provider as $item){ $total+=$item[$fieldName]; } return $total; } $provider = new

Yii2 : how to cache active data provider?

徘徊边缘 提交于 2019-12-20 10:55:42
问题 In my PostSearch model I have this code : public function search($params) { $query = Post::find()->where(['status' => 1]); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'sort'=> ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => [ 'pageSize' => 10, ] ]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere([ 'id' => $this->id, 'status' => $this->status, ]); $query->andFilterWhere(['like', 'title', $this->title]) -

Yii2 activeform ajax submit and validation

自古美人都是妖i 提交于 2019-12-20 10:39:34
问题 Currently to achieve ajax submit and validation at the same time. I'm using custom function like: $('.edit_form').submit(function (e) { e.preventDefault(); var form = $(this); var formData = $(this).serialize(); if (form.find('.has-error').length) { return false; } $.ajax({ url: form.attr("action"), type: form.attr("method"), data: formData, success: function (data) { ... }, error: function () { alert("Something went wrong"); } }); }); And here is php side, for validation my config looks like

Yii2 Render an image in DetailView

本小妞迷上赌 提交于 2019-12-20 10:39:15
问题 I am trying to render an Image in view file. My code is like below: <?= DetailView::widget([ 'model' => $model, 'attributes' => [ 'id', 'name', //'photo', [ 'attribute'=>'photo', 'value'=>('<img src =' .'uploads/' . $model->photo . ' height="100" width="100"' . '>') ], [ 'attribute' => 'birth_date', 'format' => ['date', 'dd-MM-Y'], ], 'mobile', ], ]) ?> Though the code below works: <?php echo ('<img src =' .'uploads/' . $model->photo .'>'); ?> Thanks. 回答1: Try this: [ 'attribute'=>'photo',

How to use not equal to inside a Yii2 query

[亡魂溺海] 提交于 2019-12-20 09:46:31
问题 I want to use a yii2 query in which i want to check a not equal to condition. I tried like this but it didn't give the desired results. how do i do it? $details = MovieShows::find()->where(['movie_id'=>$id]) ->andWhere(['location_id'=>$loc_id]) ->andWhere(['cancel_date'=>!$date])->all(); 回答1: In this case you need to use operator format : [operator, operand1, operand2, ...] . So your code should look like this: $details = MovieShows::find() ->where(['movie_id'=>$id]) ->andWhere(['location_id'

how to keep selected value on Yii2 html::dropddownlist?

老子叫甜甜 提交于 2019-12-20 07:48:42
问题 i have the following code in my view: <?=Html::dropdownList('region',null, ArrayHelper::map(Ethioregion::find()->all(),'region','region'),[ 'prompt' => 'Select Region..','style'=>'width:200px',]) ?> and submit button <?= Html::submitButton('Search', ['name' => 'dele','class' => 'btn btn-primary']) ?> my code working well but I have one big problem. I select a region and click the search button, the result comes correctly, and 10 result is shown per page when I click the next page, it gives me

hide a id in url yii2 using urlManager

血红的双手。 提交于 2019-12-20 06:47:03
问题 '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>' I have written this rule in url manager so that it hide id during update action i want the url should be / the id should be hidden. But no luck. eg: I have this url mysite.com/controller/update/1 i want the url to be mysite.com/controller/update 回答1: What you are trying to achieve is impossible and useless. Think about it logically. Action in this case simply won't know exactly what model should be loaded and updated. I see

Time is wrong when get datetime in yii2

五迷三道 提交于 2019-12-20 05:13:23
问题 I have a problem when I get datetime in my yii2 project. When I get datetime, the date is true but the time is wrong. I execute my code and the result is : 2016-05-02 12:30:28 whereas the time in my laptop is : 19:30. What's the problem? I use time in Indonesia. This is my code: $time = new \DateTime('now', new \DateTimeZone('UTC')); $model->tanggal_sampai = $time->format('Y-m-d H:i:s'); 回答1: You are asking for the time in the UTC time zone with new \DateTimeZone('UTC') . Either ask for it in

Pass data from a form to a controller in yii2

◇◆丶佛笑我妖孽 提交于 2019-12-20 04:49:19
问题 I am creating a page that has 3 fields - product code, startdate, enddate. When I click on the search button it should create a pdf file. 3 of these fields are without model. I've tried code - <?php use yii\helpers\Html; //use yii\grid\GridView; use kartik\grid\GridView; use kartik\export\ExportMenu; use frontend\modules\stock\models\Sellitem; use dosamigos\datepicker\DatePicker; use dosamigos\datepicker\DateRangePicker; use kartik\form\ActiveForm; /* @var $this yii\web\View */ /* @var