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
0 answers

working with multiple tables data yii2

I am new with yii2 and I am having issues printing data from 2 different tables. //at the end of the model public function getTeam() { return $this->hasOne(Team::className(), ['id' => 'team_id']); } // in the controller public function…
Tyra Pululi
  • 436
  • 1
  • 7
  • 19
0
votes
2 answers

Use andWhere under IF condition in Yii2

Just a quick question. I need to create a find query in Yii2 where an andWhere is only present if a variable is true. public function getCheckBoxItems($holiday=false) { $Items = Items::find()->where(['type'=>'checkbox']); …
Liam
  • 536
  • 8
  • 23
0
votes
1 answer

required rule not working in model for yii2basic

i have generated a model by gii for my table which by default generated required rule for some database field in rules section. But i don't want some of the fields of them to be required so i simply removed them from required portion. but this is…
rahul s negi
  • 139
  • 14
0
votes
1 answer

Build Yii2 Search Query

I am trying to build the query for search, here it is $searchResult = Candidate::find() ->select('HRMS_candidateID, HRMS_candidateFirstName','HRMS_candidateMiddleName') ->where(['LIKE', 'HRMS_candidatePrimarySkills',…
Piyush
  • 3,947
  • 9
  • 36
  • 69
0
votes
1 answer

Yii2 get insert query before saving model

Yii2 Question: Is there any way to get the current insert query before executing save? for instance $model->save(). For the current situation, save is actually inserting a row in a table. I know about executing function beforeSave($insert) but this…
Danish Ahmed
  • 171
  • 1
  • 9
0
votes
2 answers

Yii2 Join multiple tables

I have a table CREATE TABLE IF NOT EXISTS `register` ( `id` int(9) NOT NULL AUTO_INCREMENT, `student_id` varchar(15) NOT NULL, `title` varchar(100) NOT NULL, `name` varchar(250) NOT NULL, `email` varchar(50) NOT NULL, `gsm` varchar(15)…
user7282
  • 5,106
  • 9
  • 41
  • 72
0
votes
2 answers

Yii2 Model Rules Update Checking Rules For Same Record

I.E. If i update address_line1 then its giving error for mobile number allocated. While update it should not match with it self. Even if i change mobile number it should check with other user. public function rules() { return [ …
Santosh
  • 393
  • 2
  • 11
0
votes
1 answer

Yii2 GridView comparing Column content data to other controller rendered param

I've created a Yii2 Gridview widget and i'd like to display "V" mark only on row equals another renderred variable i pass from controller: $dataProvider, …
Ofershap
  • 687
  • 2
  • 7
  • 22
0
votes
1 answer

Declaring 2 relation to same table in yii2

Is it possible to declare 2 relation to the same table in yii2? Example: tournament(id, name) game(id, tournamentId, team1Id, team2Id) team(id, name) player(id, name, teamId) So here is the schema and as you can see, a game should consist of 2…
user2707590
  • 1,066
  • 1
  • 14
  • 28
0
votes
0 answers

yii\base\UnknownMethodException error when trying to $model->save() with yii2 non-table model

I'm getting Calling unknown method: app\modules\employee\models\NewEmployeeForm::save() error when trying to do $model->save(); I assumed save() method is inherited from Model, but then this happened. Do I need to write my own save method? I want to…
Reno Wijoyo
  • 253
  • 1
  • 2
  • 9
0
votes
2 answers

Yii2 dynamic connection to second database

I have a simple select in my View code. It represents list of cities and on my server there're several databases which are responsible for each city. I have my Model code and it takes city_id. Depends on it I want to connect to database and seek for…
Vadym
  • 548
  • 2
  • 8
  • 21
0
votes
1 answer

how to set autoincrement value to another column in table in yii2 model

I have form with two input fields like name,userid and the table columns are id(autoincrement,name,userid). If i save a record, the auto increment value of id will save in a column of userid. I have used a trigger for this, But this is not suitable…
JeevaRekha
  • 383
  • 1
  • 7
  • 21
0
votes
1 answer

Yii2: How do I write the below Active Query?

Using this solution, how can I get my $conditions variable to my active query? $conditions = 'main_category_id != :main_category_id', ['category_status' => 1, 'main_category_id' => 0, 'sub_category_id' => $id,'type'=> 4]; $result =…
Zack
  • 1,527
  • 2
  • 20
  • 32
0
votes
1 answer

Yii2 Access Rules Using Different Models

I'm having trouble with Yii2 Role Based Access Control. In the usual set-up, the authentication rule takes place when the identity of the current user. Like written in the docs. Authorization In my case, how can I set up the authorization (aside…
user5146984
0
votes
2 answers

Yii2 model custom rules and validations for attribute which is array

Being trying to sort this out but going nowhere with it. I have got an array as attribute for a model and I am trying to create custom validation for some of the keys in the array as required. Or even can't figure out how the attribute labels will…
Think Different
  • 2,815
  • 1
  • 12
  • 18