yii2-basic-app

yii2: Update values in two tables using single controller action?

天大地大妈咪最大 提交于 2019-12-12 06:37:19
问题 I have two tables table1 and table2 and I am trying to update row in these two table.I have same values on both table but id is different so i tried like this, my controller, public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model- >validate()) { Employee::find()->where(['Id' => $id])->one()->update(); User::find()->where(['User_id' =>$id])->one()->update(); if ( $model->save()) { return $this->redirect(['index']); } } else {

yii2 form input ajax validation will not perfom

北城以北 提交于 2019-12-11 16:32:58
问题 im trying to active ajax validation in my form according the docs i added( 'enableAjaxValidation' => true and validationUrl )with its action can anyone tell me why validation will not perform on my form ? i dont have any error in console thankyou this is my controller public function actionCreate() { $model = new Developers(); return $this->render('_form', [ 'model' => $model ]); } public function actionValidation(){ $model = new Developers(); if(Yii::$app->request->isAjax && $model->load(Yii

How to pass subquery as table name to another query in yii2

北城以北 提交于 2019-12-11 14:18:08
问题 I have a query which I am trying to convert into yii2 syntax. Below is the query SELECT project_id, user_ref_id FROM ( SELECT `project_id`, `user_ref_id` FROM `projectsList` WHERE user_type_ref_id = 1) AS a WHERE user_ref_id = '.yii::$app->user->id; I am trying to convert it into yii2 format like $subQuery = (new Query())->select(['p.project_id', 'p.user_ref_id'])->from('projectsList')->where(['user_type_ref_id' => 1]); $uQuery = (new Query())->select(['p.project_id', 'p.user_ref_id'])->from(

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

after make or change password User dont login in Yii2

微笑、不失礼 提交于 2019-12-11 08:54:01
问题 after make or edit password User i have login error 'Incorrect username or password' in Yii2 login with user 'admin' is work ( i make admin user with actionCreate1) auth_key: kYm0pvYAXY4IzuV7eYgGgtjSqoxxMNUL password: $2y$13$QqsbMW3ErXwWOPad3abDYOPzh5XLwuEvQKBhZGEEDoT0Av5l0bE2S but i make user or edit password , in login page i have error: 'Incorrect username or password' i think problem from beforeSave in Model USER User Table: id int auth_key text username text password text actionCreate:

YII2 How to allow debug/default/toolbar in accesscontrol

回眸只為那壹抹淺笑 提交于 2019-12-11 06:24:15
问题 I have the following configuration in the web.php file to force users to login first before using the app. 'as access' => [ 'class' => \yii\filters\AccessControl::className(), //AccessControl::className(), 'rules' => [ [ 'actions' => ['login', 'error'], 'allow' => true, ], [ 'actions' => ['logout', 'index'], // add all actions to take guest to login page 'allow' => true, 'roles' => ['@'], ], ], ], However I get a Forbidden (#403) error in the http://localhost/yii2/debug/default/toolbar?tag

Disable Yii Validation Error Message on focus / key up - Yii2

喜你入骨 提交于 2019-12-11 04:25:00
问题 As default, error message coming on keyup and after pressing submit button in form (If any error exist for that particular attribute). Which Is Ok. Working perfectly fine. But, Is it possible to disable error message on key up ? Means, error message, if any, should come only on pressing submit button. View <?php $form = ActiveForm::begin([ 'id' => 'register-form']); ?> <?= $form->field($model, 'first_name',['inputOptions' => ['class' => 'form-control fname','placeholder'=>'First Name']])-

Radio Button - Yii2-Basic-App

让人想犯罪 __ 提交于 2019-12-10 23:28:53
问题 In radio button, value is coming. But, I want to display the name of that value. my user_types (table) id type status created_at 1 An Individual 1 2015 2 Firm 1 2015 UserController.php (controller) public function actionRegister() { $model = new Users(); . . $modelUserType=UserType::find()->select(['id', 'type'])->where(['status' => 1]) ->indexBy("id")->column(); return $this->render('register', [ 'model' => $model, 'modelUserType'=>$modelUserType, 'module' => $this->module, ]); } register

Yii2 > How to store html output of a _form view into a string variable

不打扰是莪最后的温柔 提交于 2019-12-10 15:56:37
问题 I want to store the rendered html output of a form view which uses ActiveForm and Html Helper into a variable within my Controller. I've tried storing result of a renderPartial directly to a variable, which did not work: $htmlform = Yii::$app->controller->renderPartial('_form', ['model' => $model]); I've also tried using output buffering to echo the output into a variable, but I could not store the output: ob_start(); echo Yii::$app->controller->renderPartial('_form', ['model' => $model]);

yii2 basic multiple language

我是研究僧i 提交于 2019-12-08 07:06:57
问题 I need to make website with 2 languages in Yii2 basic framework, however, I researched tons of times on google and other search engines and I could only find yii2 advanced internalisation. I need for basic mode, please if you have source codes for yii2 basic multiple languages or if you know any link or video tutorial about yii2 basic internalisation, please kindly share with me, I would be greatly appriciated. I am looking forward from hearing from you soon. 回答1: The best tutorial is