yii2-advanced-app

Yii2 Pjax not working

拥有回忆 提交于 2019-11-30 04:14:29
I want to refresh the gridview using Pjax but somehow it is not working. Here is the code: _search.php <?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\widgets\Pjax; $this->registerJs(" $('#btnAjaxSearch').click(function(){ $.ajax({ type: 'get', data: $('.bank-search form').serializeArray(), success: function (data) { $.pjax.reload({container:\"#bank\"}); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert('error'); } }); return false; }); ", \yii\web\View::POS_END, 'bank-search'); ?> <div class="bank-search"> <?php Pjax::begin(['id' => 'bank-form']); ?> <?php

Set global language value in Yii2 application

不想你离开。 提交于 2019-11-29 17:46:14
问题 Where can I set language (based on user's cookie) globally? How to make it work in the whole application (controllers,views, etc.) ? In documentation I found \Yii::$app->language = ''; but, where I can write my logic to change the language in right way? 回答1: You should use \Yii::$app->language = ''; inside the controller that is parent to all your controllers. The parent class should be inside the components folder, and if it is not available than create the component with something like use

check a specific submit button value in controller (Yii2)

老子叫甜甜 提交于 2019-11-29 15:44:49
how to check a submit button value in controller (Yii2). I am working with multiple submit button. I tried simple php code. but it is not working. if(isset($_POST['next']) && $_POST['next']=='gotocartfive') code in view is : <?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'status')->checkbox(); ?> </div> <div class="form-group"> <?php echo Html::submitButton('NEXT',array('value'=>'gotocartfive','name' => 'next','id'=>'next_summary','class'=>'btn btn-primary pull-right')); ?> <?php echo Html::submitButton('PREVIOUS',array('value'=>'previous_four','name' => 'cartfour','class'=>

Yii2 params access within local config file in common directory

百般思念 提交于 2019-11-29 10:15:53
I'm using Yii2 advanced template, I want to access params.php in main-local.php file, I called this ways: main-local.php: 'mailer' => [ 'class' => 'myClass', 'apikey' => \Yii::$app->params['mandrill_api_key'], 'viewPath' => '@common/mail', ], and I have stored this mandrill_api_key in params.php params.php: <?php return [ 'adminEmail' => 'admin@example.com', 'supportEmail' => 'support@example.com', 'user.passwordResetTokenExpire' => 3600, 'mandrill_api_key' => 'mykey' ]; I'm getting this error: Notice: Trying to get property of non-object in C:\xampp\htdocs\myproject\common\config\main-local

Get response in JSON format in Yii2

与世无争的帅哥 提交于 2019-11-29 09:24:21
I'm trying to convert and array of response into JSON format. I have tried all the answers that were posted on SO and other websites like web1 , web2 adding header('Content-Type: application/json') and then echo json_encode($data,JSON_PRETTY_PRINT); But I'm always getting the output in text format. Can some one help me in solving this. Helpers Class: public static function renderJSON($data) { header('Content-Type: application/json'); echo json_encode($data,JSON_PRETTY_PRINT); } My Controller: if ($model->login()) { $user = User::findByUsernameOrEmail($request->post('username')); $userArray =

wbraganca yii2 dynamic form date picker issue?

会有一股神秘感。 提交于 2019-11-29 08:39:48
I am using wbraganca dynamic form. In my form one field need date picker,so i use jui date picker like below <?= $form->field($model, "[{$i}]DOB")->widget(DatePicker::classname(), [ 'language' => 'en', 'options' => ['class'=>'cust-form-control dob','placeholder'=>'Date of birth','autocomplete'=>'off','readOnly'=>true,'aria-label' => 'Date of Birth'], 'clientOptions'=>[ 'changeMonth'=>true, 'changeYear'=> true, 'yearRange'=> "1925:+0", 'dateFormat' => 'dd/mm/yy', 'maxDate' => "-1D", ], ])->label(false); ?> Earlier i am face one problem, that is the date picker open only first form, if user

YII2 : Add Dynamic form fields and their validations

故事扮演 提交于 2019-11-29 06:18:53
I am adding dynamic form fields onChange of dropdown. Both types of fields are coming from different models and go to the database in different tables. I have already defined validation rules in models. But validation are not working properly. My code is as follows: Model : <?php namespace common\models; use Yii; /** * This is the model class for table "{{%membership_features}}". * * @property integer $id * @property string $title * @property string $type * @property integer $is_new * @property integer $status * @property integer $is_deleted * @property string $created_date * @property string

How to upload files in root folder in yii2 advanced template?

老子叫甜甜 提交于 2019-11-29 05:13:42
I am unable to upload files in root folder. I uploaded files in root folder and access these files in frontend and backend application. When using the advanced template you need to decide on a common place to store your files that can be accessed by both the frontend and backend application, additionally if you want the files to be publicly accessible via the web you need to insure this location is a public folder. I tend to use the frontend/web folder as my common upload location. When uploading from the backend I write to this location. I can then use the images in the frontend. Example

Yii2 Pjax not working

℡╲_俬逩灬. 提交于 2019-11-29 01:39:05
问题 I want to refresh the gridview using Pjax but somehow it is not working. Here is the code: _search.php <?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\widgets\Pjax; $this->registerJs(" $('#btnAjaxSearch').click(function(){ $.ajax({ type: 'get', data: $('.bank-search form').serializeArray(), success: function (data) { $.pjax.reload({container:\"#bank\"}); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert('error'); } }); return false; }); ", \yii\web\View::POS

check a specific submit button value in controller (Yii2)

喜夏-厌秋 提交于 2019-11-28 09:04:25
问题 how to check a submit button value in controller (Yii2). I am working with multiple submit button. I tried simple php code. but it is not working. if(isset($_POST['next']) && $_POST['next']=='gotocartfive') code in view is : <?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'status')->checkbox(); ?> </div> <div class="form-group"> <?php echo Html::submitButton('NEXT',array('value'=>'gotocartfive','name' => 'next','id'=>'next_summary','class'=>'btn btn-primary pull-right')); ?> <