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
0
votes
1 answer

How to Basic CRUD operation in many-to-many relation in Yii2?

Hello to everyone out there I am new to Yii2. I just started learning Yii2 and got stuck in a condition where i have to use CRUD operation in case where I am having many-to-many relation in the backend. I was trying to solve it but not able to…
Neeraj Sharma
  • 71
  • 3
  • 11
0
votes
1 answer

Yii2 datetime difference calculation between two dates and inserting the difference in db

There are 3 fields in task table-> expected_start_datetime,expected_end_datetime,time_allocated While creating a task expected start and end datetime is selected and saved in the records. What I am trying to do is to find the difference between the…
deepak
  • 62
  • 2
  • 8
0
votes
2 answers

Save default values in Yii2 not working

I want to save the this following datetime while update or create so I wrote this in rules() ['createdon','default','value'=>date('Y-m-d H:i:s'),'on'=>'insert' ], ['updatedon','default','value'=>date('Y-m-d H:i:s'),'on'=>'update' ], and I declare…
Jackhad
  • 411
  • 3
  • 8
  • 19
0
votes
1 answer

besides default endpoint create custom endpoints

I am following this tutorial http://learncooltech.com/yii2-angular-how-to-create-single-page-application-in-minutes/ I got this tutorial to work and now I can see GET /books: list all books page by page; However, now I want to create some endpoints…
Asim Zaidi
  • 27,016
  • 49
  • 132
  • 221
0
votes
2 answers

PHP - Yii 2.0 Multiple images are save in folder but not saved in database

I have used use kartik\file\FileInput; (extension) for saving multiple images from single form submit. The images are save locally but are not saving in the database. Here is my Model Code media.php namespace app\models; use…
Sohaib1415
  • 53
  • 5
0
votes
5 answers

How to add column in MODEL in yii2

I have created Model called ExpertQuestion using Gii After that i added column in table from which i generated Table. So, my question is how to add column in my ExpertQuestion Model to access it. Error: Unknown Property –…
Yasin Patel
  • 5,624
  • 8
  • 31
  • 53
0
votes
2 answers

Yii2: How to generate CRUD from MySQL/MariaDB view automatically with Gii

I can quite easily generate a model from MySQL/MariaDB view with Gii, but when I try to generate CRUD, than I recieve the following error message: The table associated with frontend\models\MyModel must have primary key(s). See also the discussion…
Antonín Slejška
  • 1,980
  • 4
  • 29
  • 39
0
votes
2 answers

Yii2 date comparison not working inside rules()

I have a form, and a user have to enter a date of beginning and a date of ending. I'm using the compare attribute inside the rules method because the user can't enter a date of ending which is before the date of beginning. Here's my rules method…
0
votes
1 answer

Yii2: How to declare a has-many relation where either of two attributes match an id?

The model Team has two has-many relations to Game: public function getGamesWhereTeamIsSetAsHome() { return $this->hasMany(Game::className(), ['teamHome' => 'id']); } public function getGamesWhereTeamIsSetAsAway() { return…
Mathias
  • 334
  • 3
  • 5
  • 22
0
votes
1 answer

Displaying the fields of tables three times and saving the value uniquely

I have a problem when it comes to saving the fields of tables being displayed three times. Cant save the unique value being saved in the text fields. Kindly someone direct me to the right answer please. View code :

List of Documents

Mang Jose
  • 3
  • 2
0
votes
1 answer

How to get the base table column in inside joinWith() yii2

Order and OrderProducts. How to get the order table column joinWith(). Order::find() ->select(['order.*']) ->joinWith(['orderProducts' => function($q){ $q->select("order_id, product_id, product_name,…
Sivabalan
  • 971
  • 2
  • 18
  • 43
0
votes
2 answers

reset password validation in Yii2

I have a form in which I am trying to reset the password. I have 3 fields password, changepassword and re-enterpassword. First I need to check whether the password field matches with database password. While user signup I have used the default Yii2…
rji rji
  • 697
  • 3
  • 17
  • 37
0
votes
1 answer

yii2 modal attribute as required dynamically

I have a case where a field is mandatory, but not always mandatory. If I write the attribute as required in modal rules() like: [['my_attribute'], 'required'] then it would make the field required in every case. can I make a specific modal's…
Danish Ahmed
  • 171
  • 1
  • 9
0
votes
2 answers

YII2 creating relations in models between tables from 2 databases

I have defined 2 databases , for example return [ 'components' => [ 'db1' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=db1name', 'username' => 'db1username', 'password' =>…
0
votes
1 answer

Yii2 enable second button after the submit the form

I want to enable those two button after submit on same page using yii2. First time the button will be disabled, As i click on submit after successfully submit that buttons would be enabled. How can we perform this in yii2? Please help. thanks in…
vijay nathji
  • 1,608
  • 13
  • 23