yii2-model

Yii2: How to set default attribute values in ActiveRecord?

折月煮酒 提交于 2019-12-03 11:23:06
This may seem like a trivial question, however all of the obvious solutions that I can think of have their own flaws. What we want is to be able to set any default ActiveRecord attribute value for new records only, in a way that makes it readable before and during validation and does not interfere with derived classes used for search. The default values need to be set and ready as soon as we instantiate the class, so that (new MyModel)->attr returns the default attr value. Here are some of the possibilities and the problems they have: A) In MyModel override the init() method and assign default

how to keep selected value on Yii2 html::dropddownlist?

泄露秘密 提交于 2019-12-02 14:33:29
i have the following code in my view: <?=Html::dropdownList('region',null, ArrayHelper::map(Ethioregion::find()->all(),'region','region'),[ 'prompt' => 'Select Region..','style'=>'width:200px',]) ?> and submit button <?= Html::submitButton('Search', ['name' => 'dele','class' => 'btn btn-primary']) ?> my code working well but I have one big problem. I select a region and click the search button, the result comes correctly, and 10 result is shown per page when I click the next page, it gives me false data, I notice this is due to the selected value on the dropdownlist is reset. I tried both

What does it mean the colon in queries yii2 framework?

柔情痞子 提交于 2019-12-02 03:47:47
问题 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 status=:status'; which side is from the data base? the left side or the right side? which is a simple text and which one is a column from the DB? Im so confused. what would be another way to make the query without the colon? is it valid? why it has 'anyo =

Yii2: Configurable models inside module

北战南征 提交于 2019-12-01 14:26:34
What is the best practice of including models/activerecords within a Yii2 module in a way that they are configurable? These are just some of the problems we face when we want to use an activerecord included inside a module: Adding events & behaviors to models/activerecords provided by a module. I want to attach events and behaviors to the models included in a module using Yii2's configuration format . How can this be done? Defining relations with models/activerecords that exist outside of the module. When linking an activerecord contained inside a module to the User activerecord we can rely on

Yii2: Configurable models inside module

女生的网名这么多〃 提交于 2019-12-01 13:10:50
问题 What is the best practice of including models/activerecords within a Yii2 module in a way that they are configurable? These are just some of the problems we face when we want to use an activerecord included inside a module: Adding events & behaviors to models/activerecords provided by a module. I want to attach events and behaviors to the models included in a module using Yii2's configuration format. How can this be done? Defining relations with models/activerecords that exist outside of the

model->save() Not Working In Yii2

扶醉桌前 提交于 2019-11-26 21:19:10
问题 Previously, I was not using $model->save() function for inserting or updating any data. I was simply using createCommand() to execute query and it was working successfully. But, my team members asked me to avoid createCommand() and use $model->save(); Now, I started cleaning my code and problem is $model->save(); not working for me. I don't know where i did mistake. UsersController.php (Controller) <?php namespace app\modules\users\controllers; use Yii; use yii\web\NotFoundHttpException; use