Yii

Yii2 - How to set dynamic authTimeout in User Identity?

半世苍凉 提交于 2019-12-22 09:46:26
问题 Here, I have extended User Identity of Yii2. This is my configuration. 'user' => [ 'identityClass' => app\models\UserMaster::class, 'enableAutoLogin' => false, 'loginUrl' => ['/auth/login'], 'authTimeout' => 86400 ], Here, I have defined authTimout statically. But, What I want to do is that I want to fetch timeout value from database and set it in authTimeout . Thanks. 回答1: You can use event to set authTimeout before request will be handled: 'as beforeRequest' => [ 'class' => function (Event

JQuery UI Dialog: Password inputs causing freezing

限于喜欢 提交于 2019-12-22 09:30:50
问题 This is a odd behavior that seems to only happen in Chrome and with JQuery UI. When entering characters into a password field at first everything functions correctly. However, if you attempt to backspace to the last letter in the input, the browser locks up all client side operations. Also, if you try and highlight the characters entered and backspace the client side operations freeze. Just reaching out to see if anyone has encountered this same issue, and how they resolved it. In order to

Complex Database Queries in yii2 with Active Record

℡╲_俬逩灬. 提交于 2019-12-22 09:15:15
问题 TL;DR I have a query that works in RAW SQL but i have had little success recreating it with query builder or active record. I am working on a web application based off of the yii2 advanced application template. I have written a database query and implemented it with findbysql() returning the correct records but am having trouble translating this into active record. I originally wanted to allow the user to modify (filter) the results by means of a search form(user & date), however i have since

how to seed in Yii?

醉酒当歌 提交于 2019-12-22 09:06:48
问题 I'm wondering how one can seed in Yii a table once it is created with migration? I've got a migration with an up-method: public function up() { $this->createTable('users',array('id'=>"pk", 'login'=>'string NOT NULL')); echo "table 'users' is created.\n"; return true; } I've got as well corresponding Users model and its CRUD actions . When I try to execute another migration with an up-method public function up() { $user = new Users; $user->login = "Bob"; return $user->save(); } I get the

Yii2 Invalid Call: Setting read-only property

混江龙づ霸主 提交于 2019-12-22 09:04:23
问题 I have a Post model that has a many-many relationship with Tags . Defined in Post model: public function getTags(){ return $this->hasMany(Tags::className(), ['id' => 'tag_id']) ->viaTable('post_tags', ['post_id' => 'id']); } But Post::tags is read-only. So when I try to set them in the Controller, I get an error: Invalid Call – yii\base\InvalidCallException Setting read-only property: app\models\Post::tags The controller is using load to set all the properties: public function actionCreate(){

How to get data from Relations with joins in yii

こ雲淡風輕ζ 提交于 2019-12-22 08:54:02
问题 I am beginner in Yii, So I am asking this question. I have three different tables. First Table First table is language(id, language_name) // id is primary key. Second Table Second Table is verse(id, topic_id, surah_id, verse_text) // id is primary key, Third Table Third table is verse_translations(id, verse_id, language_id, translations_text) // id is primary key, language_id is foreign key references with language table, // verse_id is foreign key references with verse table. Now My Question

Prevent multiple clicks and ActiveForm submission in Yii 2.0.10

余生长醉 提交于 2019-12-22 08:26:19
问题 I use ActiveForms often and find it handy as it includes client-side validation scripts yii.js and yii.activeForm.js . It normally takes care of model rules and basic validation on its own. Until Yii 2.0.9: We could use following script to prevent multiple form submission due to rapid button clicks: $('form').submit(function(){ $(this).find('button[type!="button"],input[type="submit"]').attr("disabled",true); setTimeout(function(){ $('form .has-error').each(function(index, element) { $(this)

Yii restrict database connection to read-only

我们两清 提交于 2019-12-22 06:10:25
问题 I have two database connections, one that is used for most of my application data, and one that is only used for reads. Although I can setup my database user account to only allow reads, there are other people administering this system, and I want some redundancy at the application level to absolutely prevent unintended writes using the Yii's standard ActiveRecord classes. Found this bit of information on the forums, but was wondering if someone could confirm that this is a good approach and

Yii2 - Table alias with ActiveRecord

耗尽温柔 提交于 2019-12-22 05:40:32
问题 I have a table with a long name, example products_with_a_long_name . The Model name is ProductsWithALongName . Now, I have a query where I need to select many columns from this table while joining with another table. Example: ProductsWithALongName::find() ->select(['products_with_a_long_name.id', 'products_with_a_long_name.selling_price','client.name']) ->leftjoin('all_the_clients as client','products_with_a_long_name.clientId = client.id') ->where(['products_with_a_long_name.id' => $var]);

Yii - Model Unittesting an upload form

扶醉桌前 提交于 2019-12-22 05:33:09
问题 I have the following uploadform model class TestUploadForm extends CFormModel { public $test; public function rules() { return array( array(test, 'file', 'types' => 'zip, rar'), ); } My Question is, how can I unit test this? I've tried something like: public $testFile = 'fixtures/files/yii-1.1.0-validator-cheatsheet.pdf'; public function testValidators() { $testUpload = new TestUploadForm; $testUpload->test = $this->testFile ; assertTrue($testUpload ->validate()); $errors= $testUpload -