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

How to add custom controller to extension in vender folder in yii2?

I have an extension yii2-admin for RBAC, and I would like to add to this extension another controllers, views, models etc. Because in this module I would like to keep all operations who admin like CRUD for User table and for another. What is the…
2
votes
1 answer

Yii2 model save returns true but there is no change in MySQL

Actually, If I update my model in the action of controller(in this case it is actionTest) it gets updated. Here is my code: public function actionTest() …
Yusuf
  • 53
  • 4
2
votes
1 answer

Yii2 - Updating single field of another model from update form

Longtime passive user of StackExchange and I am at a loss here. It's probably super simple, but I'm stuck. I've used gii-enhanced to build the models and CRUD. I have two models: ordenes and facturas. When I'm updating a facturas model I can link…
Carlos
  • 93
  • 2
  • 7
2
votes
2 answers

Yii2 models - active record joinWith + andWhere date selection

I like to select specific related data on two related Yii2 models. Both models stuck in a 1:n relation. The relation is working fine! Order model: @property integer $id Order model relation define: /** * @return \yii\db\ActiveQuery */ public…
lin
  • 17,956
  • 4
  • 59
  • 83
2
votes
1 answer

Yii2 unique validator ignored

In the rules() of my RegisterForm model: [ 'user_username', 'unique', 'targetClass' => 'app\models\User', 'message' => 'This username is already been taken.' ], In my controller: $model = new RegisterForm(); if ( $model->load(…
keeg
  • 3,990
  • 8
  • 49
  • 97
2
votes
2 answers

Yii2: Status 'enabled' & 'disabled' helper function - dynamic use

I would like to combine 2 functions together, to consolidate code, and to be dynamic depending on how it is used. I do not know if this is possible. First, lets lay out the basic use. In my example, I have Post and PostCategory models (and CRUD…
Wade
  • 3,757
  • 2
  • 32
  • 51
2
votes
1 answer

How to do use nested condition in AndWhere in yii2

Before marking as duplicate question,kindly read it. I have different problem here. I want to generate this kind of Query using yii2 search model. select * from t1 innerjoin t2 on (t1.id = t2.id) where ((t1.price >= '1000' and t1.price <= '5000') OR…
uiTeam324
  • 1,215
  • 15
  • 34
2
votes
2 answers

Yii2 afterSave. Using changedAttributes show error

I have this weird error in my Yii2 Model's AfterSave Function When I do this public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); if(!$insert): print_r($changedAttributes);exit; …
ck_arjun
  • 1,367
  • 1
  • 11
  • 19
2
votes
1 answer

After adding new column "name" to user table in yii2 advanced, data not getting saved in it

After assigning all required values to user model (column which i have added also). When I am using $model->save() data for all default attributes getting saved except the one I have added. I trying insert via REST call. If there is any other way to…
akhil
  • 347
  • 1
  • 3
  • 16
2
votes
1 answer

What does it mean the colon in queries yii2 framework?

I'm totally new in yii2 and I want to know what does it mean the colon in the query? I have made a research about binding parameters, but in the yii2 documentation says: // returns all inactive customers $sql = 'SELECT * FROM customer WHERE…
JavaNoob
  • 21
  • 1
2
votes
1 answer

Yii2 Gridview filter by permission

I have a super admin, that can create users and can assign specific locations for each user. This is stored in a simple table, where we get the ID of the user and the ID of the location. Then, I have a table of clients. Each client also has a…
2
votes
3 answers

Select2 kartik number value change to index value

I have data like this: I use these data to fill the select2 kartik combobox, this is my yii2 code, echo \kartik\widgets\Select2::widget([ 'attribute' => 'pembuatSoal_id', 'model' =>…
Maulana Yusuf
  • 337
  • 2
  • 4
  • 16
2
votes
0 answers

Jquery show render page in gridview yii2

I am trying to create feedback page by put gridview on the page to show the feedbacklist, and I have plan to put the list replay under the current comment. This is the following code I made: 'columns' => [ [ 'attribute' =>…
1
vote
2 answers

Getting unknown property on Model attribute in Yii2-advanced

I am having a model class in my Yii2-advanced application which was having some attributes. public function rules() { return [ [['SESSION_TITLE', 'SESSION_DESCRIPTION', 'TRAINER_ID'], 'required'], [['TRAINER_ID','IS_ACTIVE',…
Ramisha Mukhtar
  • 321
  • 1
  • 12
1
vote
2 answers

Yii2: Multiple inverse relations to same model?

How do I handle multiple inverse relations pointing to the same active record? For example: class Bicycle extends ActiveRecord { public function getFrontWheel() { return $this ->hasOne(Wheel::class, ['id' =>…
mae
  • 14,947
  • 8
  • 32
  • 47