yii2

Yii2: How to convert data type value of a JSON PHP array?

≡放荡痞女 提交于 2021-02-10 15:29:12
问题 I am using Yii2 framework to create this JSON array: "data": [ { "id": 201, "name": "John", "age": "30" } ] The age is a string and I need it to be an integer , that is, without quotation marks. Like this: "data": [ { "id": 201, "name": "John", "age": 30 } ] This is the PHP function that create the JSON array: $persons['data'] = Persons::find() ->select([ 'id', 'name', 'age' ]) ->asArray() ->all(); 回答1: You can use JSON_NUMERIC_CHECK flag as second parameter of json_encode() or \yii\helpers

Subquery in SELECT using Yii2 ActiveRecord

♀尐吖头ヾ 提交于 2021-02-10 05:54:06
问题 Is it possible to convert this kind of SQL into ActiveRecord query in Yii2: SELECT *, (select count(*) from pendaftar where pendaftar.prodi_pilihan_1 = a.id_prodi_penerima)as jum1, (select count(*) from pendaftar where pendaftar.prodi_pilihan_2 = a.id_prodi_penerima)as jum2 FROM prodi_penerima as a I have two relational models that are Pendaftar and ProdiPenerima . This is Pendaftar model: ... * @property ProdiPenerima $prodiPilihan1 * @property ProdiPenerima $prodiPilihan2 ... /** * @return

Yii2 GridView with ArrrayDataProvider search

孤街浪徒 提交于 2021-02-09 17:55:31
问题 I need help with search model for ArrayDataProvider. Let's say i have an array: $cities = [ ['city' => "Chicago", 'year' => 1984], ['city' => "Washington", 'year' => 2001], ['city' => Manchester", 'year' => 1997], //and so on... ]; I create an ArrayDataProvider: $provider = new \yii\data\ArrayDataProvider([ 'allModels' => $catalog, 'sort' => [ 'attributes' => ['city', 'year'], ], ]); Then I create a GridView: echo \yii\grid\GridView::widget([ 'dataProvider' => $provider, 'filterModel' => (new

Yii2 GridView with ArrrayDataProvider search

爷,独闯天下 提交于 2021-02-09 17:53:12
问题 I need help with search model for ArrayDataProvider. Let's say i have an array: $cities = [ ['city' => "Chicago", 'year' => 1984], ['city' => "Washington", 'year' => 2001], ['city' => Manchester", 'year' => 1997], //and so on... ]; I create an ArrayDataProvider: $provider = new \yii\data\ArrayDataProvider([ 'allModels' => $catalog, 'sort' => [ 'attributes' => ['city', 'year'], ], ]); Then I create a GridView: echo \yii\grid\GridView::widget([ 'dataProvider' => $provider, 'filterModel' => (new

Yii2 GridView with ArrrayDataProvider search

谁说我不能喝 提交于 2021-02-09 17:50:48
问题 I need help with search model for ArrayDataProvider. Let's say i have an array: $cities = [ ['city' => "Chicago", 'year' => 1984], ['city' => "Washington", 'year' => 2001], ['city' => Manchester", 'year' => 1997], //and so on... ]; I create an ArrayDataProvider: $provider = new \yii\data\ArrayDataProvider([ 'allModels' => $catalog, 'sort' => [ 'attributes' => ['city', 'year'], ], ]); Then I create a GridView: echo \yii\grid\GridView::widget([ 'dataProvider' => $provider, 'filterModel' => (new

Yii2 GridView with ArrrayDataProvider search

浪子不回头ぞ 提交于 2021-02-09 17:49:05
问题 I need help with search model for ArrayDataProvider. Let's say i have an array: $cities = [ ['city' => "Chicago", 'year' => 1984], ['city' => "Washington", 'year' => 2001], ['city' => Manchester", 'year' => 1997], //and so on... ]; I create an ArrayDataProvider: $provider = new \yii\data\ArrayDataProvider([ 'allModels' => $catalog, 'sort' => [ 'attributes' => ['city', 'year'], ], ]); Then I create a GridView: echo \yii\grid\GridView::widget([ 'dataProvider' => $provider, 'filterModel' => (new

How to fetch data from database and set as submenus in yii2?

一笑奈何 提交于 2021-02-08 11:00:17
问题 I have a widget menu in yii2: <?= \yii\widgets\Menu::widget([ 'encodeLabels' => false, 'options' => ['id' => 'dock'], 'items' => [ ['label' => 'ab...', 'template' => '<i class="fa fa-dashboard"></i><a href="{url}">{label}</a>', 'options' => ['class' => 'launcher dropdown hover'], 'submenuTemplate' => "\n<ul class='dropdown-menu'>\n{items}\n</ul>\n", 'items' => [ ['label' => 'a', 'url' => ['users/..'], 'visible' => Yii::$app->user->isGuest ], ['label' => 'b', 'url' => ['users/..'], 'visible' =

Undefined class DateTime in PHPStorm

戏子无情 提交于 2021-02-07 11:30:56
问题 I want to use class DateTime but PHPStorm says me that "Undefined class DateTime" and my PHP version is 5.5.9-1 . I'm using PHPStorm version 2016.1 and i'm working with Yii2 framework (if it'll give you any useful information). So how can i use with correct lint default PHP classes? 回答1: You need to use backslash \DateTime or add use DateTime; 来源: https://stackoverflow.com/questions/38562376/undefined-class-datetime-in-phpstorm

How to configure yii2-solr extension

我是研究僧i 提交于 2021-02-07 04:38:36
问题 I want to use yii2-solr extension in one of my projects. How can I configure this extension. Nothing is mentioned on the extension page. Has anyone used this extension? Any help would be appreciable. Thank you. I found the extension on github repo . In readme file it is mention to configure it as follows: 'solr' => [ 'class' => 'sammaye\solr\Client', 'options' => [ 'endpoint' => [ 'solr1' => [ 'host' => '10.208.225.66', 'port' => '8983', 'path' => '/solr' ] ] ] ], But after doing all this I

Error:“Call to undefined method ping.” Using Yii2 and Swiftmailer

耗尽温柔 提交于 2021-01-29 09:53:00
问题 Any help would be highly appreciated. I do not understand what I am doing wrong. I have used Swiftmailer before and it has never been this difficult to configure it. I am using an advanced Yii2 project. This is part of my backend/config/main.php (I have tried with backend/config/main-local.php, common/config/main.php and common/config/main-local.php just in case): .... 'components' => [ 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'useFileTransport' => false, 'transport' => [ 'class' =>