yii2

Yii2: Assigning javascript event to anchor tag in yii2

徘徊边缘 提交于 2019-12-11 12:16:32
问题 how to assign javascript onclick event to the anchor tag what is the mapping of it in yii2 <a style="margin-left: 30px;" href="" onclick="$('#createTeamForm').show(500); $('#createTeamForm').css('display','')"> Create Team</a> 回答1: You can achieve this like below: \yii\helpers\Html::a('Create Team',\yii\helpers\Url::to('url'),['onclick'=>"$('#createTeamForm').show(500);$('#createTeamForm').css('display','')",'style'=>'margin-left: 30px;']); 来源: https://stackoverflow.com/questions/27356300

Yii2 datepicker in kartik gridview not working

别来无恙 提交于 2019-12-11 12:14:29
问题 I'm using kartik gridview and I want to add a datepicker to the search fields I'm also using datecontrol This is what I got, but the validation is not working: Gridview date picker: [ 'attribute'=>'date', 'value' => function ($model, $index, $widget) { return Yii::$app->formatter->asDate($model->date); }, 'filterType' => GridView::FILTER_DATE, 'filterWidgetOptions' => [ 'pluginOptions' => [ 'format' => 'dd-mm-yyyy', 'autoclose' => true, 'todayHighlight' => true, ] ], 'width' => '160px',

Yii2 How to prevent autoloading of assetsbundle of any widget?

自作多情 提交于 2019-12-11 11:40:42
问题 I am using \yii\jui\AutoComplete It automatically loads the JuiAssets. Is there any way to prevent loading files of JuiAssets? I want to use my own version of files. In the previous version of Yii Framework, we had option to prevent loading the associated css and js files of any widget. Is there any way to change the AssetBundle for any jui Widget, without editing its core files? 回答1: Yes, you can easily customize any AssetBundle to fit your needs: 1) Through application config: return [

Traversing Hierarchy Tree Adjacency List Model in Yii2

有些话、适合烂在心里 提交于 2019-12-11 10:58:39
问题 I was stuck in one logic i can't understand how it would be done and traverse the list. Actually I was creating a category list that would be further used in creating the products. I wanted the category list should be in the form of parent and its sub nodes like adjacency list model. Database: id categoryname parent [id is the foreign key for the parent] 1 a 1 2 b 2 3 c 2 4 e 2 5 f 3 6 g 4 Fetching the details with Activequerry in yii2 $rows = Category::find() ->asArray() ->all(); $rows array

Change handler value when user input in textarea unique data

纵然是瞬间 提交于 2019-12-11 10:47:07
问题 I use bootstrap-slider Kartik extension for Yii2. I want to make slider handler responsive for textarea inputs. For this moment my textarea is responsive for sliding via slide event . before after How it works right now 回答1: What i understand from your question you are trying to update or refresh the slider if you update the value inside an input. If that is correct you have to use javascript to bind the input event to the input field associated with the slider and then call the setValue

Remove controller name from URLs in Yii2

偶尔善良 提交于 2019-12-11 10:36:09
问题 How can I remove the controller name from URLs in Yii2? I'm aware of simple aliases, but I'm not sure how to apply aliases to a little bit more complex rule, like the following one: 'rules' => [ 'public/<seo_url:.*?>/<category_id:\d+>/<product_id:\d+>' => 'public/product' ] This will create a rule so URLs like /product/this-is-a-slug/94/12 will call the actionProduct in my Public controller. How can I make an alias that would call that same action if I try to access a product using this URL:

Yii2 Button with Parameter

我是研究僧i 提交于 2019-12-11 10:19:45
问题 I have this button in my Yii2 project: Html::a('label', ['/attributes/index'], ['class'=>'btn btn-primary']) ; The button is located in the page: /site/view Now what I want to do is pass a parameter when this button gets clicked to the attributes/index page from the site/view page. To be more specific it is the ID that I want to pass of a particular record from a DB I am viewing. Cheers. 回答1: You can pass parameters as key => value pairs after the route: Html::a('label', ['/attributes/index',

yii2 url rule with named parameter of type array

为君一笑 提交于 2019-12-11 10:17:12
问题 how can i create an url rule, with a named parameter of type array? now i have this, working: 'urlManager' => [ 'rules' => [ 'page/<id:\w+>' => 'cms/page/view', ], ], to map 'page/welcome' to module=cms , controller=page , action=view , param $id=welcome now i would like to have the url like this, with a variable number of folder-name parts: /page/folder1/folder2/.../folderN/pagefile for an action: function actionPage(array $folders, string $id) { // expecting: // $folders == [ 'folder1',

Yii2 - How to set Time in Log messages?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 10:16:54
问题 I am using EmailTarget in Yii2 and I am logging messages like this. Yii::info('Log message example','mail'); After successful execution, I am receiving mail like this: 2018-07-31 09:01:12 [127.0.0.1][user@example.com][-][info][mail] Log message example By default Yii2 generating log messages and displaying time in GMT format. How can I configure time in these log messages? 回答1: This log target uses date() for date formatting, so if you're getting date with wrong timezone, you probably have

Username and Password not accepted in yii2

╄→尐↘猪︶ㄣ 提交于 2019-12-11 09:55:45
问题 I have a error with yii2, I can't send emails via yii with a email account. If my password is correct :( This is my code: web.php 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'transport' => [ 'class' => 'Swift_SmtpTransport', 'host' => 'smtp.gmail.com', 'username' => 'user@hya.com.mx', 'password' => 'passwd', 'port' => '587', 'encryption' => 'tls', ], ], 'log' Controller.php Yii::$app -> mailer -> compose() -> setFrom('users@hya.com.mx') -> setTo('jhon@hya.com.mx') -> setSubject('Test')