Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 12:51
    xiaoyi510 commented #17734
  • 11:55
    buttflattery commented #17218
  • 11:30
    gagatust commented #17734
  • 11:02
    My6UoT9 commented #17218
  • 11:01
    My6UoT9 commented #17218
  • 11:01
    My6UoT9 commented #17218
  • 10:55
    buttflattery commented #17218
  • 10:36
    brussens commented #17633
  • 10:13
    rob006 commented #17633
  • 10:09
    brussens commented #17633
  • 09:48
    rob006 commented #17633
  • 09:41
    brussens commented #17633
  • 09:40
    brussens commented #17633
  • 09:37
    tomlutzenberger commented #17734
  • 09:32
    xiaoyi510 commented #17734
  • 09:32
    xiaoyi510 commented #17734
  • 09:24
    tomlutzenberger commented #17734
  • 09:16
    toatall opened #17735
  • 07:41
    xiaoyi510 opened #17734
  • 07:21
    alex-code commented #17705
Lachee
@Lachee
error
silencer903
@silencer903
Hello everyone. someone can help me for problem with dataprovider+gridview+pjax ?
silencer903
@silencer903
i find answer)
Bpragnya
@Bpragnya
Hi this is pragnya can any one help me
Bpragnya
@Bpragnya
Hi this is pragnya can any one help me with conditional validation in ajax/ gii form in which i kept a conditional validation on check box if it is checked other dependent field is mandatory
It is working perfectly in non ajax but not in ajax form. To check i
Wrote a piece of code to alert value if checked not working in ajax
Any one plz help me with this problem as soon as possible
matrixbot
@matrixbot
shurik2k5 Hello! Show you code.
Bpragnya
@Bpragnya
hello shurik2k5

In model.php

[ ['section_incharge_designation_id1','incharge_from_dt1'],
'required',
'message' => 'Cannot be null',
'when' => function($model) {

                    return ($model->field1==1);
                    },
                    'enableClientValidation' => false
                    , 'whenClient' => "function (attribute, value) {

                                                     if(document.getElementById('field1').checked)
                                                            {return true  ;}
                                                            else{return false  ;}

                                     }"

                            ],

In controller
public function actionCreate()
{
$request = Yii::$app->request;
$model = new EmsSectionMst();
$section_details_model=new EmsSectionInchargeDtl();

    if($request->isAjax){
        /*
         *   Process for ajax request
         */
        Yii::$app->response->format = Response::FORMAT_JSON;
        if($request->isGet){
            return [
                    'title'=> "Create new EmsSectionMst",
                    'content'=>$this->renderAjax('create', [
                            'model' => $model,'section_details_model'=>$section_details_model
                    ]),
                    'footer'=> Html::button('Close',['class'=>'btn btn-default pull-left','data-dismiss'=>"modal"]).
                    Html::button('Save',['class'=>'btn btn-primary','type'=>"submit"])

            ];
        }else if($model->load($request->post()) && $model->validate())
        {

                    return [
                    'forceReload'=>'#crud-datatable-pjax',
                    'title'=> "Create new EmsSectionMst",
                    'content'=>'<span class="text-success">Create EmsSectionMst success</span>',
                    'footer'=> Html::button('Close',['class'=>'btn btn-default pull-left','data-dismiss'=>"modal"]).
                    Html::a('Create More',['create'],['class'=>'btn btn-primary','role'=>'modal-remote'])

                    ]; 

        }else{
            return [
                    'title'=> "Create new EmsSectionMst",
                    'content'=>$this->renderAjax('create', [
                            'model' => $model,'section_details_model'=>$section_details_model
                    ]),
                    'footer'=> Html::button('Close',['class'=>'btn btn-default pull-left','data-dismiss'=>"modal"]).
                    Html::button('Save',['class'=>'btn btn-primary','type'=>"submit"])

            ];
        }

    }else{
        /*
        *   Process for non-ajax request
        */
        if ($model->load($request->post()) && $model->validate()
                //&& $model->save()
                ) {

            return $this->redirect(['view', 'id' => $model->section_id]);
        } else {
            return $this->render('create', [
                'model' => $model,
                    'section_details_model'=>$section_details_model
            ]);
        }
    }

}
not working in ajax
matrixbot
@matrixbot
shurik2k5 paste code in markdown code block
Bpragnya
@Bpragnya
````
In model.php


[        ['section_incharge_designation_id1','incharge_from_dt1'],
                        'required',
                        'message' => 'Cannot be null',
                        'when' => function($model) {

                        return ($model->field1==1);
                        },
                        'enableClientValidation' => false
                        , 'whenClient' => "function (attribute, value) {
                                //alert(document.getElementById('field1').value);
                                                         if(document.getElementById('field1').checked)
                                                                {return true  ;}
                                                                else{return false  ;}

                                         }"

                                ],
In controller.php

 public function actionCreate()
    {
        $request = Yii::$app->request;
        $model = new EmsSectionMst();  
        $section_details_model=new EmsSectionInchargeDtl();

        if($request->isAjax){
            /*
             *   Process for ajax request
             */
            Yii::$app->response->format = Response::FORMAT_JSON;
            if($request->isGet){
                return [
                        'title'=> "Create new EmsSectionMst",
                        'content'=>$this->renderAjax('create', [
                                'model' => $model,'section_details_model'=>$section_details_model
                        ]),
                        'footer'=> Html::button('Close',['class'=>'btn btn-default pull-left','data-dismiss'=>"modal"]).
                        Html::button('Save',['class'=>'btn btn-primary','type'=>"submit"])

                ];
            }else if($model->load($request->post()) && $model->validate())
            {
                        echo"<br>post<br>";
                        print_r($model->load($request->post()));
                        echo"<br>vali<br>";
                        print_r($model->validate());
                        echo"<br>deta<br>";
                        print_r($section_details_model->validate());
                        echo "<br>sdfsf<br>";
                        print_r($_POST);
                        /*         die();

                        return [
                        'forceReload'=>'#crud-datatable-pjax',
                        'title'=> "Create new EmsSectionMst",
                        'content'=>'<span class="text-success">Create EmsSectionMst success</span>',
                        'footer'=> Html::button('Close',['class'=>'btn btn-default pull-left','data-dismiss'=>"modal"]).
                        Html::a('Create More',['create'],['class'=>'btn btn-primary','role'=>'modal-remote'])

                        ];  */
            }else{
                return [
                        'title'=> "Create new EmsSectionMst",
                        'content'=>$this->renderAjax('create', [
                                'model' => $model,'section_details_model'=>$section_details_model
                        ]),
                        'footer'=> Html::button('Close',['class'=>'btn btn-default pull-left','data-dismiss'=>"modal"]).
                        Html::button('Save',['class'=>'btn btn-primary','type'=>"submit"])

                ];
            }

        }else{
            /*
            *   Process for non-ajax request
            */
            if ($model->load($request->post()) && $model->validate()
                    //&& $model->save()
                    ) {
                print_r($_POST);

                die();
                return $this->redirect(['view', 'id' => $model->section_id]);
            } else {
                return $this->render('create', [
                    'model' => $model,
                        'section_details_model'=>$section_details_model
                ]);
            }
        }

    }
Bpragnya
@Bpragnya
In view.php

<div class="ems-section-mst-forma">

    <?php $form = ActiveForm::begin(['id' => 'sectionmst-form',
                    //'enableAjaxValidation' => true,
                    /* 'validateOnSubmit'=>true,
                    'enableAjaxValidation' => true,
                    'enableClientValidation' => true, */
                    //'id' => 'ajax'
                    ]); ?>
 $i=1;
    foreach ($site_dtls as $dtls)
    { ?>
   <!--<input type="checkbox" id= $dtls->site_id?> value= $dtls->site_id?>><b>Active in $dtls->site_code?></b><br>-->
   <?= $form->field($section_details_model, 'field'.$i)->checkbox(['id'=>'field'.$i,
                   //'id'=>$dtls->site_id,
                   'value'=>$dtls->site_id,'label'=>'Active in '.$dtls->site_code,
                   'onchange'=>"show_other_fields(this,'$i');"
   ]);?>
<div class="row">
      <div class="col-sm-12 col-md-12 col-lg-12 hidden-item" id="<?= $i?>section_incharge_designation_id_div">
   <?= $form->field($section_details_model, 'section_incharge_designation_id'.$i)->widget(Select2::className(),[
                   'data'=>Fields_detail::get_all_designations(),

                   'options'=>['autofocus' => true,'prompt'=>'Select Designation','id'=>$i.'section_incharge_designation_id'],
   ])->label('Section Incharge Designation in '.$dtls->site_code);?>

   </div>
  </div>
<?php

   $i++;
    }?>
matrixbot
@matrixbot
shurik2k5 paste model code again
Bpragnya
@Bpragnya
In model.php (conditional validation)

    public function rules()
    {
        return [
                [['official_email_id1','official_email_id2'],'email','message'=>'Not a valid Email Address'],
    [        ['section_incharge_designation_id1','incharge_from_dt1'],
                        'required',
                        'message' => 'Cannot be null',
                        'when' => function($model) {

                        return ($model->field1==1);
                        },
                        'enableClientValidation' => false
                        , 'whenClient' => "function (attribute, value) {
                                //alert(document.getElementById('field1').value);
                                                         if(document.getElementById('field1').checked)
                                                                {return true  ;}
                                                                else{return false  ;}

                                         }"

                                ],
];
}
Bpragnya
@Bpragnya
````
``
    [        ['section_incharge_designation_id1','incharge_from_dt1'],
                        'required',
                        'message' => 'Cannot be null',
                        'when' => function($model) {

                        return ($model->field1==1);
                        },
                        'enableClientValidation' => true
                        , 'whenClient' => "function (attribute, value) {
                                alert('hgello');
                                                         if(document.getElementById('field1').checked)
                                                                {return true  ;}
                                                                else{return false  ;}

                                         }"

                                ],
matrixbot
@matrixbot
shurik2k5 paste you code to gist https://gist.github.com/
Bpragnya
@Bpragnya
again?
Bpragnya
@Bpragnya
Yeah done
matrixbot
@matrixbot
shurik2k5 Im model
'enableClientValidation' => false
Bpragnya
@Bpragnya
if i made it false how would validation work !!
although i made if false and tried too
but it didnt works
image.png
image.png
matrixbot
@matrixbot
shurik2k5 php <?php $form = ActiveForm::begin(['id' => 'sectionmst-form', 'enableAjaxValidation' => true, ]); ?>
uncomment enableAjaxValidation in view
Bpragnya
@Bpragnya
image.png
didnot work again by checking flag and submitting it it again refresh whole page and validatinig first field not others where i kept contional valition
image.png
image.png
Karugi Gitau
@gkarugi

Hey guys..

I am having a problem with rest routes - am getting 404.

I have a model - Product

<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "products".
 *
 * @property int $id
 * @property string $name
 * @property int $supplier_id
 */
class Product extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'products';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['supplier_id'], 'integer'],
            [['name'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'supplier_id' => 'Supplier ID',
        ];
    }
}

Controller - ProductController

<?php

namespace app\Controllers;

use app\models\Product;
use yii\data\ActiveDataProvider;
use yii\rest\ActiveController;

class ProductController extends ActiveController
{
    public $modelClass = 'app\models\Product';
    public $serializer = [
        'class' => 'yii\rest\Serializer',
        'collectionEnvelope' => 'items',
    ];

    public function actionIndex()
    {
        var_dump('here');
    }
}

and routes in url manager

...
 'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => true,
            'rules' => [
                ['class' => 'yii\rest\UrlRule', 'controller' => 'product'],
            ],
        ],
...

What am I missing?

Alex
@alexssdd
@gkarugi
    public function actions()
    {
        $actions = parent::actions();
        unset($actions['index']);

        return $actions;
    }
paratout
@paratout
Hi
Lachee
@Lachee
The web Request gets confused when trying to resolve ID's with letters in them
/transactions/10 works fine
/transactions/10,5 works fine
but when you do
/transactions/10,5f
it gets confused and thinks that the action is 10,5f instead of view like the others have
resolve() in the web/Request is the cause
actually I should say its the URL manager
Lachee
@Lachee
nevermind, I resolved the issue myself by duplicating the rest\UrlRule and changing its allowed-tokens to [a-zA-Z0-9][a-zA-Z0-9,-_]*
hmm, still cannot get
11111111138,024d7994-a26c-4c20-9894-13934840fc31 working using that, but I guess I can live without the dashes
Alexander Makarov
@samdark
liyuze
@liyuze

Server suddenly returns error code 500

It is found that the IO speed of the hard disk of the php-fpm process is 130Mb/s , and the corresponding file is /runtime/logs/app.log

Q A
Yii version 2.0.22
PHP version 7.1
Operating system linux

main.php

'log' => [
    'traceLevel' => YII_DEBUG ? 3 : 0,
        'targets' => [
        [
            'class' => 'yii\log\FileTarget',
            'levels' => ['info','error', 'warning'],
            'logVars' => ['_GET','_POST'],//记录全局变量的参数,$_GET,$_SERVER...,默认会增加一条info记录
            'logFile' => '@app/runtime/logs/-app.log',
            'maxFileSize' => 1024 * 2000,       // 2G
            'maxLogFiles' => 1,
        ]
    ],
],

When I read the source code in vendor/yiisoft/yii2/log/FileTarget.php, I found that I should set rotateByCopy = false.

file:vendor/yiisoft/yii2/log/FileTarget.php

/**
* @var bool Whether to rotate log files by copy and truncate in contrast to rotation by
* renaming files. Defaults to `true` to be more compatible with log tailers and is windows
* systems which do not play well with rename on open files. Rotation by renaming however is 
* a bit faster.
*
* The problem with windows systems where the [rename()](https://secure.php.net/manual/en/function.rename.php)
* function does not work with files that are opened by some process is described in a
* [comment by Martin Pelletier](https://secure.php.net/manual/en/function.rename.php#102274) in
* the PHP documentation. By setting rotateByCopy to `true` you can work
* around this problem.
*/
public $rotateByCopy = true;

But I don't think this configuration will cause the server to stop serving.Then I found a bit of confusion.

file:vendor/yiisoft/yii2/log/FileTarget.php

    public function export()
    {
        $logPath = dirname($this->logFile);
        FileHelper::createDirectory($logPath, $this->dirMode, true);

        $text = implode("\n", array_map([$this, 'formatMessage'], $this->messages)) . "\n";
        if (($fp = @fopen($this->logFile, 'a')) === false) {
            throw new InvalidConfigException("Unable to append to log file: {$this->logFile}");
        }
        @flock($fp, LOCK_EX);   ########### lock file
        if ($this->enableRotation) {
            clearstatcache();
        }
        if ($this->enableRotation && @filesize($this->logFile) > $this->maxFileSize * 1024) {
            @flock($fp, LOCK_UN);   ########### unlock file
            @fclose($fp);
            $this->rotateFiles();   ########### when rotateByCopy = true , copying file content to aother file is slow (2GB size). Causes multiple php-fpm processes copy files at the same time
            ########### Why unlock file before rotateFiles() @see:https://github.com/yiisoft/yii2/pull/3563#issuecomment-425630598
            ########### Maybe we need a separate lock file for rotateFiles().
            // ...
        } else {
            // ...
        }
        // ...
    }

Is my idea right?