yii2

Yii2: Populating model field with value from many-to-many relation

孤人 提交于 2019-12-11 06:17:23
问题 We are trying to set-up our REST API in a way that a user can only retrieve data related to his account. Uptill now, We've only had a public API and it all worked like a charm. The public API will still get used, so we started from scratch. We have a User model, extending ActiveRecord and implementing IdentityInterface . A User will have a relation to a Customer model (Many:Many, but at least one). A User will have only one MASTER Customer. The above is saved in the database using 3 tables

Yii2-admin RBAC: Get roles from database and display as Dropdownlist on Signup/User registration

本秂侑毒 提交于 2019-12-11 06:14:13
问题 I am looking for a way to enable an administrator to assign users roles after registering them from the backend. I have configured yii2-admin in yii2 advanced and I have roles already set in the database table. However I want to get the roles on the user registration form as a dropdown list and the administrator should be able to select a role and assign to the user. The roles on the dropdown list should be those lower than that of the admin or equivalent to his...i.e if there is a sysadmin

yii2 gridview filter date

人走茶凉 提交于 2019-12-11 06:08:34
问题 I have in my gridview a date. I want to type it in the format "29.11.2018" . But in my table, the date is in the format "2018-11-29" . So it doesnt filter. my index.php: [ 'attribute'=>'enddate', 'format' => 'date', 'label' => 'Ablaufdatum' ], my searchmodel: $query->andFilterWhere(['like', 'user', $this->user]) ->andFilterWhere(['like', 'enddate', $this->enddate]); 回答1: You can use mysql:DATE_FORMAT() AND php:date() to make sure it always compares in the same format and you can use any of

Many datepickers in one form yii2

风格不统一 提交于 2019-12-11 06:02:26
问题 I would like to have various datepickers in my form. Unfortunetely, only the first field acts as supposed. Here's my code: <?php for ($i = 0; $i < 4; $i++) { ?> <div class="row"> <div class="col-md-1"> <?= ($i+1).'.' ?> </div> <div class="col-md-3"> <?= $form->field($pres_rules[$i], 'date')->textInput() ?> </div> <div class="col-md-3"> <?= $form->field($pres_rules[$i], 'time')->widget(TimePicker::className(), [ 'pluginOptions' => [ 'showMeridian' => false, 'defaultTime' => '12:00' ],

How to make that GridView buttons update and delete just only visible for admins?

无人久伴 提交于 2019-12-11 06:02:02
问题 I am new to Yii2 and I have 3 kind of user rights : Admin , moderator and user . I have my GridView and I don't want to show for the user the Update and Delete buttons, just only the GridView . How should I do that? Here is my actionCreate , there is an input form: public function actionCreate() { $model = new Project(); $model->scenario = Project::SCENARIO_CREATE; if ($model->load(Yii::$app->request->post())) { if ($model->save()) { Yii::$app->getSession()->setFlash('success', Yii::t('app',

how to display default value in dropDownlist

徘徊边缘 提交于 2019-12-11 05:54:26
问题 I have two dropDownlist in index, when I select the submit button it will get action in controller, and it performs some operations and again render the index with gridview, but the Selected dropDownList become blank, how can I set the default in dropDownllist?? Any suggestion should be appreciatable... this is my view <div class="col-sm-12" align="center"> <?= $form->field($model, 'fk_int_payroll_month')->dropDownList( ArrayHelper::map(TblPayrollMonth::find()->all(), 'pk_int_payroll_month_id

how to show json data in yii2 gridview

谁说我不能喝 提交于 2019-12-11 05:32:45
问题 I want to display json data in gridview.I get data in console window. and I want to display in gridview.how to do that. below givencode In controller public function actionCompanyinfo(){ $text_in_search = $_GET['text_in_search']; $left_items_cat = ltrim($_GET['left_items_cat']); if($left_items_cat == "Companies"){ $query = (new \yii\db\Query()) ->select(['c.name', 'c.id']) ->from(['companies as c']) ->where('c.name LIKE :query') ->addParams([':query'=>'%'.$text_in_search.'%']) ->all();

How to check my field `username` on unique in table `User` except current user's username in Yii2

半腔热情 提交于 2019-12-11 05:16:49
问题 In view my field username always filled by current user's username. And it always (on submit) sends username value to my InformationForm and validate it on unique like next: [['username'], 'unique', 'targetAttribute' => 'username', 'targetClass' => '\common\models\User', 'message' => 'This username can not be taken.'], And it say's that this username has already been taken. So i want to check my value username just then, whet it's not my username. It's like My current username in database ->

Steps to send mail using sendgrid mailer function in yii2?

吃可爱长大的小学妹 提交于 2019-12-11 05:16:33
问题 I am trying to get the mail using sendgrid in Yii 2 but it doesn't seem to work.Can any one tell me steps of sendgrid in yii2 . 回答1: You can use https://github.com/bryglen/yii2-sendgrid#yii-2-bryglen-sendgrid Installation: composer require --prefer-dist bryglen/yii2-sendgrid "*" common/config/main.php 'components' => [ ... 'sendGrid' => [ 'class' => 'bryglen\sendgrid\Mailer', 'username' => 'your_user_name', 'password' => 'your password here', //'viewPath' => '@app/views/mail', // your view

Yii2 jQuery not working in IE11

南楼画角 提交于 2019-12-11 04:56:10
问题 The Problem I'm trying to create a page that updates a specific records field in a table when a checkbox is clicked (ideally without refreshing the page). I thought jQuery/AJAX would work for me. Apparently not. I've been struggling with this for a while, so I decided to scale it back and really simplify it to figure out what's not working. The updating of the table is fine (from Chrome), the not-refreshing isn't. And none of it works from IE11. It's currently hosted on my local machine, so