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

Replace Yii2 core class

I am looking to override the default Model \yii\base\Model class with an extended version I have created. For arguments sake lets say I have it in backend\components\Model I have tried putting both of these in the bootstrap config file but nothing…
nicky
  • 787
  • 2
  • 12
  • 27
1
vote
2 answers

How to show form fields while updating a record in Yii2

I am using wbraganca / yii2-dynamicform. I am able to create a new record. There are two models that I am using to create records. The data is saved into both of the tables. field($model, 't_name')->textInput(['maxlength' => true])…
Moeez
  • 494
  • 9
  • 55
  • 147
1
vote
1 answer

pagination of SqlDataProvider not work me when use the call of a stored procededure

I'm using the SQLDataProvider to call a procedure that returns a list of records but I can't get it to work what i'm trying is: $dataProvider = new SqlDataProvider([ 'sql' => "CALL ErroresEnHoras(:project_id, :fecha_iniciop,…
1
vote
3 answers

Define multiple scenarios and validate with multiple scenarios in Yii 2 model

In model I have defined multiple scenarios: public function rules() { return [ [['in_quantity'], 'required','on'=>['stockIn']], [['out_quantity'], 'required','on'=>['stockOut']], ]; } Is it possible to use both scenario…
1
vote
2 answers

Yii2 sort by with calculations in an ActiveDataProviderRecord

I would like to add a groupby with cacluations in yii2 ActiveDataProvider. SO currently i have the following fields in my database tbl_products id, products, pts_log,pts_chum SO i would like to group my data with the formula pts_log * pts_chum /…
Geoff
  • 6,277
  • 23
  • 87
  • 197
1
vote
1 answer

Yii2 filtering products by attributes filter

I have a database of products which I'd like to filter by Attributes. I have a section of products. Each product should have a collection of attributes e.g. color and weight. I have 3 products. First product has attribute: color = red, second has…
RBR
  • 13
  • 4
1
vote
2 answers

Yii2 query with and or in where condition

Hi iam trying to covert this query as active record format SELECT cmaindb, eshdr1, ascsnr, takpplz, takpadr FROM ts_stats WHERE (cmaindb = 'tam' OR cmaindb = 'soc') AND (nproduktiv = 1) OR (cmaindb = 'tc') AND (nabrfirm = 5) AND…
Shibon
  • 1,552
  • 2
  • 9
  • 20
1
vote
2 answers

Yii2: Can I create rules and custom error messages that apply when DELETING a model?

I want to delete a model but it might have related records in another model when will prohibit me doing so. How can I best use the already defined relationships to check if delete will be successful? Potentially there could also be non-relationship…
TheStoryCoder
  • 3,403
  • 6
  • 34
  • 64
1
vote
1 answer

How to create a model object in yii2 by string name?

I need to create a model by string name that it is a variable. function($modelName){ $modelName= "backend\\models\\".$modelName; $modelClass = Yii::createObject([ 'class' =>…
Rahman
  • 410
  • 6
  • 26
1
vote
1 answer

Yii2 virtual attribute naming - very strange uppercase/lowercase problem?

I am using Yii2 and I have the virtual attribute notes2 (that is used by the GUI functions instead of database attribute notes): class Order extends \yii\db\ActiveRecord { public function getnotes2() { return iconv('UTF-16LE',…
TomR
  • 2,696
  • 6
  • 34
  • 87
1
vote
2 answers

Yii2 Setting read-only property

Good day everyone When I try to create a client, I get an error: Setting read-only property: app\models\form\ClientForm::Clientclient How can I fix this error? This is my ClientClient(model) class ClientClient extends \yii\db\ActiveRecord { /** *…
Sergej
  • 68
  • 4
  • 11
1
vote
2 answers

Yii2 - Assign a "fix" condition

I am building an app, where an account can have many services, all the information is related to a service. In example: Account A has 3 services and each service has pages. In order to avoid someone modifying the service_id when saving a page, at…
Eduardo
  • 1,781
  • 3
  • 26
  • 61
1
vote
2 answers

Recreate database tables from Yii2 models

I wrote an application in Yii2, and unfortunately, we've lost all the database back ups. What we now have is the application files only. Is there a shorter way of recreating the 98 database tables based on the existing models? I notice that some 22…
Paul Wakhungu
  • 322
  • 2
  • 18
1
vote
0 answers

yii2 role based scenario

I'm developing a yii2 rest api based app that has different roles of users (Admin, Customer, Shop, Service). I'm planning to use scenarios with one user database table contains union of fields that requires all roles. (80% is the same) I would like…
Bence
  • 63
  • 4
1
vote
1 answer

How to search posts with two or more certain tags via PostSearchModel?

Please help me to understand, how to do it. For example I have 3 tags: A; B; C. And 3 posts Post 1 with tags: A B; Post 2 with tags: B C; Post 3 with tags: A B C. I need to search only posts with tags A,B,C. In this example only Post 3 contains…