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
3
votes
3 answers

How to search with an array in Yii2 search model

public function actionIndex() { $searchModel = new SubjectSearch(); $searchModel->search()->query->andFilterWhere(['in','subjectID',[1,2,3]]); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return…
Tsz Fung Li
  • 57
  • 1
  • 1
  • 9
3
votes
4 answers

How to manage password during update user profile in Yii2

I can add user successfully, For Password hashing I am using md5() But when I update user it is giving an error. Here are the model rules: public function rules() { return [ [['firstname', 'lastname', 'username', 'email', 'role',…
user2678776
3
votes
1 answer

Yii2. Many inputs for one Model/DB field

How such inputs could be translated into DATE field in DB? Customer insisted on such way to input user birthdate. First my thought was simply to concat in one field in beforeValidate, but after this inputs won't be able to display date, that was…
D.R.
  • 2,540
  • 3
  • 24
  • 49
3
votes
1 answer

yii2 password rules pattern

you can at yii2 in the Model Rules enter patterns in passwords ? Tips for a rule that at least one uppercase character and at least one number ? Thanks so much Rules ['password', 'pattern' => '(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20}'],
Saba
  • 115
  • 1
  • 15
3
votes
3 answers

Yii2 different form fields on create and on update scenario

In my Model I have created different scenarios. I have one form which is rendered bu both create and update method. The form fields are as follows Form.php errorSummary($model, $options =…
Mohan Prasad
  • 682
  • 1
  • 9
  • 34
3
votes
1 answer

Yii2 grid view filter sql

Hi every one I have a grid view with SQLDataProvider and I'm doing the ModelSearch. Every tutorial on internet are with ActiveDataProvider and I don't want to use ActiveRecord because of the way I'm using my database. So my question is : how can I…
Samaël Villette
  • 318
  • 3
  • 25
3
votes
3 answers

How to create a directory inside a directory in yii2 and upload file into that directory

I have a form ['enctype' => 'multipart/form-data']]); ?> field($userformmodel, 'user_image')->fileInput(); ?> 'btn btn-primary']) ?> …
3
votes
1 answer

How to partition table on Yii2?

A table named demo,now need to partition it just like demo1,demo2,demo3,....,demo10 So how to partition the table on Yii2? I probably known should add a method getTableName in Model.
tanteng
  • 648
  • 1
  • 6
  • 11
3
votes
2 answers

yii2 get activerecords by relation column

I need to select ActiveRecord's that have related AR's with specific column value. Situation: 'User' may have many 'Branches' - via junction table, and Branch is related to Department. I have department_id, and I want to select Users, that have…
Ixon
  • 63
  • 4
3
votes
1 answer

Yii2 activerecord unexpected results with limit in with() callback function

I'm having a problem building a query with Yii2. Let's say we have four related models: Customer, Order, Orderitem and Orderitempicture. Order is related to Customer, Orderitem is related to Order, and Orderitempicture is related to Orderitem. Below…
Rayan Salhab
  • 131
  • 8
3
votes
5 answers

Convert Yii to Yii 2.0: getRestParams()

How to write this line of code from Yii to Yii 2.0: Yii::app()->getRequest()->getRestParams() ?
delux
  • 1,694
  • 10
  • 33
  • 64
2
votes
2 answers

How to add different and common classes in radioList() in yii2

This is the chtml of radio-button in one of my update form. field($model, 'customer_sel')->radioList(array('customer' => 'Customer', 'supplier' => 'Supplier', 'excludecustomer' => 'Exclude Customer', 'all' => 'All'))->label('Select…
code-droid
  • 190
  • 12
2
votes
2 answers

yii2 combine data from multiple queries in ActiveDataProvider

Am trying to combine data from different queries into a single active record for the purpose of pagination I have two different databases with similar table, that is db1 tbl_products id,quantity,price Now on db2 db2 tbl_products …
Geoff
  • 6,277
  • 23
  • 87
  • 197
2
votes
3 answers

Yii2 Gridview error

I want to display column from another table in gridview. In my controller actionIndex: public function actionIndex() { $user_id = \Yii::$app->user->identity->id; $queryFile = PowerGen::find(); $queryFile…
2
votes
1 answer

Yii 2.0 - Trying to get property of non-object

I try to change the "ID Kategori"(Category ID) to "Nama Kategori" (Category Name), the Category ID is in product table and has a relation to category table. for the gridView im using kartik-v gridView i know the error is at return…
1 2
3
21 22