Questions tagged [yii2-model]

Use this tag if your question relates to the Yii2-model-class or one of its descendants.

This tag should be used whenever your question relates to the \yii\base\Model class or one of its descendants like \yii\db\ActiveRecord.

320 questions
1
vote
1 answer

In Yii2 Unable to show custom column from model in gridview

Below is the dataprovider query i have used in search function of the UserSearch model, extended from User model. I am trying to show the value of 'entries' in the gridview but unable to access the column 'entries'. Please help. $query =…
Vivek Palanisamy
  • 148
  • 1
  • 10
1
vote
1 answer

Yii2 cannot save model data in controller

I am trying to get value from title and I did but after pressing save button the title is not saving in database $model = new Translation(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $getfromtitle =…
1
vote
1 answer

Field inside Active Form with Array

I have a dropDownList with multiple select and when i goes to the actionUpdate, i wanna the content of dropDownList selected (correct content). Array: array (size=3) 0 => object(backend\models\AliHasAliPlanRef)[100] private…
Juan.Queiroz
  • 207
  • 1
  • 3
  • 13
1
vote
1 answer

yii2 connect tables in gridview

I have main table and several sub tables. Main table Product : productID / productNameID / productColorID and subtables productName : productNameID / name productColor : productColorID / name In main table I just insert IDs of sub tables. And to get…
David
  • 4,332
  • 13
  • 54
  • 93
1
vote
0 answers

Yii2: Sorting by calculated column

I have one table like: name startDate endDate units price and I show them in a gridview for a given year as follows (index.php in views): $gridColumns = [ 'name', [ 'attribute' => 'january', 'format' => 'currency', …
farrusete
  • 435
  • 9
  • 24
1
vote
0 answers

Yii2 object oriented model API throwing error on execution

I am creating an api using Yii2 framework . But it throws error during its execution. BankDetailsController.php
user7408344
1
vote
1 answer

Yii2 Combine 2 unrelated models with some shared properties into one Gridview

I have 2 separate models (for 2 separate tables) containing some similar properties, which I want to combine into one GridView. The models are unrelated. Model 1: +----+------+----------------+-----+ | id | name | email | age…
Dxx
  • 934
  • 2
  • 11
  • 41
1
vote
1 answer

Yii2: model rules inheritance on behavior

I dont know if there is another way to get this: UserModel.php public function behaviors() { //I use array_merge() because UserModel extends from another custom model. return array_merge( …
nacesprin
  • 392
  • 7
  • 16
1
vote
1 answer

Disable ActiveForm Clientside Validation on button other than submit Yii2

I have an upload excel to DB form. It has 1 File input and 2 buttons 'Upload' and 'Delete All'. Problem Scenario: I don't want client-side activeform validation on 'Delete All' as File is not required here. Code:
Ankur Soni
  • 5,725
  • 5
  • 50
  • 81
1
vote
1 answer

How to set scenario in Join Query object in Yii2

How to set scenario in object created from Join Query in Yii2 My query is $model = Answers::find() ->joinWith('question') ->where(['request_id' => $Request->id])->all(); I am getting data in model object. Now when i try to…
Ninja Turtle
  • 1,293
  • 2
  • 24
  • 50
1
vote
1 answer

Why does yii2 mongodb date filter returns no results when using between condition

I am using yii2 mongodb latest version, when i try to get record in a given date range i get null records. my codes are as follow Function that filter records received today that is in my model public function today(){ $finder = self::find(); …
ELIJAH MWANGI
  • 21
  • 3
  • 6
1
vote
1 answer

UPDATE using WHERE in Yii2 not working

I am checking for expiry in 'orders' table. If 'end_date' is less or equal to Todays date, then I am changing status to "Expired". But I guess something is going wrong. Below is the Piece of code. $new_date = new \DateTime(); $today =…
Ankur Soni
  • 5,725
  • 5
  • 50
  • 81
1
vote
1 answer

Calculate Avg Sum of days from column with type DATE in yii2 with diiference from today date

I need help with query or way to do with single query in yii2. Application is in yii2 , working on admin dashboard. I need to show the Avg days of all products in stock from today date that has been in system which are enabled (in short average age…
Vikram
  • 35
  • 1
  • 10
1
vote
0 answers

Override ActiveRecord find() method with two behaviors

How can override ActiveRecord find() method with two behaviors? I am using two behaviors in model and each of one has override the find() method. Thanks
msoa
  • 1,339
  • 3
  • 14
  • 33
1
vote
1 answer

Show only 5 item in yii2 List view

In my yii2 application list view need to show only 5 product limit. This my View page $dataProvider, 'itemView' => '_item', 'summary' => '', ] ); ?> and…
Biju s
  • 420
  • 1
  • 7
  • 16