yii2

Calling a function on grid action coumn click

独自空忆成欢 提交于 2019-12-25 09:06:18
问题 I have a grid in yii that has an action column with a custom button I would like to call function when the grid button is clicked but i get an error This is my code: [ 'class' => 'kartik\grid\ActionColumn', 'template' => '{approve}{new}{reject}', 'buttons' => [ 'approve' => function ($url, $model) { return Html::button('<i class="fa fa-check"></i>', ['value' => Url::to('approvetruck?id='.$model->id),'style' =>'background:none;border:none;','id' => 'approve','onclick'=>'alert('.$model->id.')']

Bind dynamically generated forms for ajax validation?

泄露秘密 提交于 2019-12-25 08:37:25
问题 I am generating many forms on a page dynamically using JS. Each form corresponds to a yii2 model (which has its rules set up for each attribute). I would like each form to validate all elements (name, email text inputs) to validate with ajax (as they would normally do as if I only had one form). I am finding that using the method pointed out here: https://yii2-cookbook.readthedocs.io/forms-activeform-js/ `$('#contact-form').yiiActiveForm('validateAttribute', 'contactform-name');` gives JS

How can I show error message in login form modal?

浪子不回头ぞ 提交于 2019-12-25 08:29:24
问题 I am following this link to create a login modal. Now my login action is public function actionLogin() { if (!Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); }else{ return $this->renderAjax('login', [ 'model' => $model, ]); } } and in another view test.php , I have a button echo Html::button('Create New Company', ['value' => Url::to(['site/login']), 'title' => 'Creating

Yii2 oracle 11g gii relations timeout

烂漫一生 提交于 2019-12-25 07:47:24
问题 I have: Windows Server 2012 R2 wampserver 3.0.6 64bit yii2 php_oci8_12c enabled, php_pdo_oci enabled, oracle instantclient-basiclite-windows.x64-12.1.0.2.0 System Path defined according added mod_fcgid 2.3.9 to Apache added oci8 2.0.12 Thread Safe x64 for PHP 5.6 (replaced old php_oci8_12c.dll) I see PDO for Oracle in phpinfo. I have a db_o.php config file: return [ 'class' => 'yii\db\Connection', 'dsn' => 'oci:dbname=//SOME_IP_ADDRESS:PORT/YOUR_SID;charset=UTF8', 'username' => '', 'password'

pretty url in yii2 not working

折月煮酒 提交于 2019-12-25 07:38:19
问题 In web.php i have this 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ '<controller:\w+>/<action:\w+>' => '<controller>/<action>', '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', '<controller:\w+>/<id:\d+>' => '<controller>/view', ], ], apache for this folder configured like this php.conf file <VirtualHost *:80> AssignUserId alexzander alexzander ServerName localhost DocumentRoot /home/alexzander/Dropbox/study/3year/2/php/ <Directory

Custom userIdentity class in yii2

南楼画角 提交于 2019-12-25 04:43:34
问题 I want to create custom userIdentity class according to my specific requirements .Here the code is <?php namespace app\models; use yii\web\IdentityInterface; use app\models\dbTables\Users; class UserIdentity implements IdentityInterface{ const ERROR_USERNAME_INVALID=3; const ERROR_PASSWORD_INVALID=4; const ERROR_NONE=0; public $errorCode; private $_id; private $_email; private $_role; private $_name; public function findIdentityById($id){ $objUserMdl = new Users; $user = $objUserMdl::findOne(

Yii2: Adding dynamic DateControl fields from related model to a form

风格不统一 提交于 2019-12-25 04:38:20
问题 I have three models: User, Job and UserJob. The models User and Job have n:m relation. In the user form I need to dynamically add new jobs. In the model User I get the jobs related to the current user: public function getUserJobs() { return UserJob::find() ->where(['user_id' => $this->id]) ->orderBy('start DESC') ->all(); } In the views/user/_form.php are the existing jobs added to the form as follows: if (isset($userJobs)) { $i = 0; foreach ($userJobs as $job) { $i++; ... echo $form->field(

Prevent users from accessing a url directly Yii 2

半世苍凉 提交于 2019-12-25 04:34:07
问题 I have this piece of code that if the user clicks on it the link will be replaced by text making it unable to be clicked again. The problem now is that if the user access it directly in the url so it will simulate a link click. So how do I prevent users from accessing urls directly? <?php $isAdded = ActiveSubject::find()->where(['clientid' => $_user,'subjectid' => $subjects['subjectid'],])->exists(); if($isAdded): ?> <b><p class="text-muted">ADDED</p></b> <?php else: ?> <p> <?= Html::a('<b

yii2 form validation not working

非 Y 不嫁゛ 提交于 2019-12-25 04:26:08
问题 How to know if the validation has been triggered in yii2 active form? I am using $('#formId').yiiActiveForm('validate', true); to validate the form, but it always returns undefined. 回答1: Trigger the form validation try this : var $form = $("#formId"), data = $form.data("yiiActiveForm"); $.each(data.attributes, function() { this.status = 3; }); $form.yiiActiveForm("validate"); I've create a function to validating active form in javascript, it will be return true/false. Maybe usefull : function

How to displaying the datas in Yii2 index like cardview

爷,独闯天下 提交于 2019-12-25 03:54:56
问题 I'm trying to displaying the datas (for example: projects table) in my Yii2 advanced project and i just need to know how can display these things in my index? i mean, i couldn't find any tutorial or discussion about this in the internet. but with one diffrence, i know we can use DetailView::widget or Gridview widget or something like that, but, where should i put those codes into it? i mean, how can use these widgets for each item like a cardview. exactly like below: https://play.google.com