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

The upload variable is empty in yii2

i want add uploadFile to: https://github.com/thyseus/yii2-message i added public $file2 in Message.php in model and this is my rules in model: public function rules() { return [ [['title'], 'required'], [['file2'],…
Saltern
  • 1,305
  • 2
  • 16
  • 42
1
vote
1 answer

Database Access Objects batchInsert() yii2 run another function after each record is inserted

I am using batchInsert() function of Yii2 Database Access Objects. I need to run another function like sending email from PHP code after each record is inserted.What is the workaround to achieve this? Or is it possible to get all AUTO_INCREMENT ids…
user7282
  • 5,106
  • 9
  • 41
  • 72
1
vote
1 answer

Yii2 model custom validate method / function does not work

I want to validate my fine_amount against 2 input date. But it does not return any error. Without validating this method it saved data. I also looked into Yii2: how to use custom validation function for activeform? but for me no solution. Below…
Destroyer.0211
  • 113
  • 1
  • 3
  • 13
1
vote
1 answer

How to pass subquery as table name to another query in yii2

I have a query which I am trying to convert into yii2 syntax. Below is the query SELECT project_id, user_ref_id FROM ( SELECT `project_id`, `user_ref_id` FROM `projectsList` WHERE user_type_ref_id =…
rji rji
  • 697
  • 3
  • 17
  • 37
1
vote
2 answers

Yii2 how to create rule (filter) for all model's attributes?

It's boring to apply "trim" filter for each attribute in the model. Any idea does Yii2 have something like that: ['*', 'filter', 'filter' => 'trim'],
1
vote
2 answers

Yii2 remove optional created field from form

I have a "BTeam" model class with attributes id, name, created. I generated this with Gii. I added "TimestampBehavior" which fills the "created" field during model creation with the current timestamp. How can I remove the field from the "add"…
breakline
  • 5,776
  • 8
  • 45
  • 84
1
vote
0 answers

Best way to make my models reusable in other application Yii2

I'm currently working on two different yii2 project templates. Relevant with my question, those projects have the same set of models, and ahead of time, I know that those models can also be used in different yii2 applications. So I'm thinking if…
Chisskarzz
  • 171
  • 2
  • 16
1
vote
1 answer

Class 'Device' does not exist or has syntax error

can anyone helping me? im stuck
Asyiq M
  • 13
  • 5
1
vote
2 answers

How to create a relation query with hasOne and onCondition?

Because I've got an index (user_id,lesson_id) I want to query with that index. In the case of the image it does not use the index, right ? NOTE: USER_ID it is a INTEGER VALUE and not a FIELD. //the following SQL it is my expecting: //not generate…
hhniao
  • 49
  • 8
1
vote
1 answer

How to send model values in controller in Yii2

I have a view in which I have used GridView and DetailView. In my controller I am sending a model via it's ID. So in this way my GridView is working. Controller 1 public function actionViewcreated($id) { $model=$this->findModel($id);//the…
Moeez
  • 494
  • 9
  • 55
  • 147
1
vote
2 answers

Yii2 how to save old informations to history-table?

thanks for all stackoverflow members, I learned a lot from here. I have a question about "beforeSave", I want save the old data to history-table in the database, for example if the user change anything I want save the old informations in the…
1
vote
2 answers

Yii2 access to module instance from model

I want to know if there is a way to access at the module instance from a model. In my module configuration I have some components which I need to call in a model class, the model is defined only inside my module. I know the method…
MarBer
  • 535
  • 1
  • 5
  • 22
1
vote
1 answer

How i can force an yii2 module to use a specific connection for all his models?

on a module I have add a component named db where i put, like the main Yii component, the data for database connection, I need in my module use everytime the db specified in his configuration for all models and not the main database connection, how…
MarBer
  • 535
  • 1
  • 5
  • 22
1
vote
1 answer

Yii2 TimeStampBehaviour doesn't work

I've already spent many of hours, but I can't figure it out what is the problem yet. I'm trying to implement a TimeStampBehaviour (and Blamable, but neither of them are working now). My model class:
wyzard
  • 543
  • 5
  • 17
1
vote
1 answer

want to send email with url,it is working but it is redirecting me to another url i.e host/projectname/site/login

public function actionRequestPasswordReset() { $model = new UserSignup(); if ($model->load(Yii::$app->request->post())) { $email = $model->email; $row = UserSignup::find()->where( ['email' => $email])->exists(); if($row !=…
shikha
  • 19
  • 1
  • 6