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

Yii model overriding based on constant

I need to change model class in my yii2 project. Because of a change in database so all the query of model class need to be converted according to new database table. But I want to the old db configuration also because if something went wrong in my…
truesource
  • 397
  • 3
  • 20
0
votes
1 answer

Yii2. Date validation rule wrong format

I have such validation rule ['birthdate', 'date', 'format' => 'Y-m-d'], and passing such value 2002-03-11, but recive validation error The format of Birthdate is invalid. What am I doing wrong?
D.R.
  • 2,540
  • 3
  • 24
  • 49
0
votes
1 answer

yii2 PJAX How to show modal after doing pjax reload?

i have code like this : $('.btnRemove').on('click', function(){ var id = $(this).attr('id'); $.ajax({ type :'POST', dataType : 'json', data : ({delid :…
yosafat
  • 243
  • 1
  • 4
  • 17
0
votes
1 answer
0
votes
3 answers

Yii2. Model::loadMultipe. How to load class fields too?

How to load not only DB attributes, but fields too with loadMultipe? I have such a model class Person extends ActiveRecord { public $birthdate_month; public $birthdate_day; public $birthdate_year; ... public function rules() …
D.R.
  • 2,540
  • 3
  • 24
  • 49
0
votes
2 answers

Yii2. Multiple model items in one form

I have such ActiveForm in view. How to allow user in this view select number of children (form items) and submit all number of children the same model items.
D.R.
  • 2,540
  • 3
  • 24
  • 49
0
votes
1 answer

yii2 How to order via relation by COUNT?

I have a organizers, which do tournaments where a player can participate. So I have the tables organizer, tournament, participation, player. I made a relation in the organizer model that gives me all players who ever payer in a tournament organized…
Mathias
  • 334
  • 3
  • 5
  • 22
0
votes
0 answers

Yii2: Select last 3 rows of each item

Given these tables/fields: people: id socialID name peopleStats: id socialID drVisitsAmount receipAmounts operationsAmount Im trying to get last 3 records from peopleStats (ordered by id DESC) for a given array of socialIDs (3 records per each…
farrusete
  • 435
  • 9
  • 24
0
votes
0 answers

yii2 switch button that render page with pjax

I'm trying to make a form that changes the input according to the button pressed, using pjax of yii2, no page loads. My view
Saba
  • 115
  • 1
  • 15
0
votes
1 answer

How to set date format depending on incoming other attribute value in Yii2 model

I want to save Task model, but cannot do it without define date. I have boolean attribute allDay (checkbox in view) and if it set in TRUE date format should be d-m-Y; else 'd-m-Y H:m'. How to define this condition in rules() method? Next code not…
Oleg Sg
  • 5
  • 4
0
votes
3 answers

Yii2 suggestion for two or more users

I'm beginner to yii2, I want to FOLLOW a suggermento Which way to create two users with different capabilities. Can you give me an example of how to create two types of users? Thanks so much
Saba
  • 115
  • 1
  • 15
0
votes
2 answers

Multiple ActiveForms on same page is not working in yii2

I have bootstarp tabs in yii2 view page Each tab have different model's active form. Client side was working fine on all the forms. But form submission on the forms is not working. Only one form is working fine. others are not submitting the form. …
Sivabalan
  • 971
  • 2
  • 18
  • 43
0
votes
0 answers

accessing another model value in beforeSave() in yiii2

A model fields and B model fields in same form Ex: public static function tableName() { return 'a'; } public function rules() { return [ [['id','b_id'], 'id'], ]; } public function beforeSave($insert) { //I want to save b…
Yasar Arafath
  • 605
  • 1
  • 9
  • 30
0
votes
2 answers

How to use javascript in Yii2 model class?

In a custom validation function in my model class. I need to use javascript code. for that i used registerJs function but i am getting error:- Calling to undefined function registerJs() I also tried calling it by including View class i.e.,…
Ninja Turtle
  • 1,293
  • 2
  • 24
  • 50
0
votes
1 answer

yii2 save date format how 1970-01-01 Database

I have a problem saving the data in the database . It saves them as 1970-01-01 , invalid date . I would read them as dd-mm-yyyy and convert them to the database in yyyy-mm-dd . my model public function behaviors() { return [ [ …
Saba
  • 115
  • 1
  • 15