yii2

Yii2 REST create with fields()

末鹿安然 提交于 2020-01-16 05:12:27
问题 Let's say that I had the following API set up: Controller: <?php namespace app\modules\v1\controllers; use yii; class ResourceController extends \yii\rest\ActiveController { public $modelClass = 'app\modules\v1\models\Resource'; } Model: use yii; class Resource extends \yii\db\ActiveRecord { public static function tableName() { return 'ResourceTable'; } public function fields() { return [ 'id' => 'ResourceID', 'title' => 'ResourceTitle', ]; } } where my table only has the two columns,

Setting empty text in kartik dynagrid

做~自己de王妃 提交于 2020-01-15 10:54:10
问题 Am using kartik dynagrid and i would like to setup a text that shows when the dataprovider returns empty The grid echo DynaGrid::widget([ 'columns' => $columns, 'showPersonalize' => true, 'emptyText'=>'Sorry all pr have pritems',///-----------------This is what i had set 'options' => ['id' => 'assignsolic-grid'], 'gridOptions' => [ 'options' => ['id' => 'grid'], 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'showPageSummary'=>false, 'pager' => [ 'firstPageLabel' => 'First',

Setting empty text in kartik dynagrid

那年仲夏 提交于 2020-01-15 10:53:45
问题 Am using kartik dynagrid and i would like to setup a text that shows when the dataprovider returns empty The grid echo DynaGrid::widget([ 'columns' => $columns, 'showPersonalize' => true, 'emptyText'=>'Sorry all pr have pritems',///-----------------This is what i had set 'options' => ['id' => 'assignsolic-grid'], 'gridOptions' => [ 'options' => ['id' => 'grid'], 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'showPageSummary'=>false, 'pager' => [ 'firstPageLabel' => 'First',

Setting empty text in kartik dynagrid

风格不统一 提交于 2020-01-15 10:53:09
问题 Am using kartik dynagrid and i would like to setup a text that shows when the dataprovider returns empty The grid echo DynaGrid::widget([ 'columns' => $columns, 'showPersonalize' => true, 'emptyText'=>'Sorry all pr have pritems',///-----------------This is what i had set 'options' => ['id' => 'assignsolic-grid'], 'gridOptions' => [ 'options' => ['id' => 'grid'], 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'showPageSummary'=>false, 'pager' => [ 'firstPageLabel' => 'First',

error yii2 upload Call to a member function saveAs() on null

北慕城南 提交于 2020-01-15 10:43:57
问题 I am new programmer world and ask for your help guys, I have error "Call to a member function saveAs() on null" This code in models [['file'],'file'], this code in controllers $docfileload = $model->docname; $model->file = UploadedFile::getinstance($model,'file'); $model->file->saveAs('uploads/'.$docfileload.'.'.$model->file->extension); $model->save(); //save path in db $model->docfile = 'uploads/'.$docfileload.'.'.$model->file->extension; this code in _form <?= $form->field($model,'file')-

error yii2 upload Call to a member function saveAs() on null

被刻印的时光 ゝ 提交于 2020-01-15 10:43:08
问题 I am new programmer world and ask for your help guys, I have error "Call to a member function saveAs() on null" This code in models [['file'],'file'], this code in controllers $docfileload = $model->docname; $model->file = UploadedFile::getinstance($model,'file'); $model->file->saveAs('uploads/'.$docfileload.'.'.$model->file->extension); $model->save(); //save path in db $model->docfile = 'uploads/'.$docfileload.'.'.$model->file->extension; this code in _form <?= $form->field($model,'file')-

Yii2 Active record how create relation between mongo models

…衆ロ難τιáo~ 提交于 2020-01-15 04:58:06
问题 I have 2 classes which extends \yii\mongodb\ActiveRecord for example Users and Posts relations between this classes User have many posts. 回答1: The same way as using relational databases: public function getPosts() { return $this->hasMany(Posts::className(),['_id'=>'user_id']); } 来源: https://stackoverflow.com/questions/29347016/yii2-active-record-how-create-relation-between-mongo-models

how to place yii2 form error in title of anchor tag

拥有回忆 提交于 2020-01-15 03:45:06
问题 how to place yii2 form error in title of anchor tag This is my code $form = ActiveForm::begin([ 'id' => 'login-form', 'options' => ['class' => 'form-horizontal'], 'fieldConfig' => [ 'template' => ' {label} <div class="error-block"> <a href="#" title="{error}">error</a> </div> {input} ', 'errorOptions' => ['tag' => null] ], ]); I want to add error in title of anchor tag in YII2 <a href="#" title="{error}">error</a> 回答1: You need to display the error text inside the anchor tags title attribute,

Change the button action in Gridview based on a model attribute value Yii2

牧云@^-^@ 提交于 2020-01-14 05:46:07
问题 I generated a simple application by CRUD generator... In the View page there is a action column assigned with some buttons like view, update, delete.... all I want is to create a status button.... If the status is inactive it should ask me and change the status into active and vice versa This is my code: 'suspend' => function($url, $model) { return Html::a( '<span class="btn btn-xs btn-danger icon-remove bigger-80"style="margin-left:5px;"></span>', $url, ['title' => Yii::t('app', 'Inactivate'

Yii2 and storing data in database as UTC

末鹿安然 提交于 2020-01-14 03:12:06
问题 I'm using Yii2 and I was wondering how it decides what timezone to store the data in the database as? I have noticed the $defaultTimezone which seems to indicate it simply controls what timezone your input data is supposed to be when passing it to functions such as the the asTime function and it uses the formatter timezone to convert said data into the correct time output. But I'm wondering how do you make sure it is inserting the data into your database in the right timezone so then the