Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 15:56
    DrummerKH commented #17166
  • 15:53
    WinterSilence commented #18955
  • 12:50
    bizley closed #18957
  • 09:40
    machour review_requested #18957
  • 09:33
    bizley synchronize #18957
  • 09:02
    bizley review_requested #18957
  • 09:02
    bizley milestoned #18957
  • 09:02
    bizley labeled #18957
  • 09:02
    bizley opened #18957
  • 07:38
    bizley closed #18954
  • 07:38
    bizley commented #18956
  • 07:38
    bizley closed #18956
  • 06:48
    bizley synchronize #18956
  • 06:47
    bizley commented #18955
  • Oct 18 22:01
    samdark commented #18940
  • Oct 18 22:01
    samdark closed #18909
  • Oct 18 22:01
    samdark closed #18940
  • Oct 18 22:01
    samdark synchronize #18940
  • Oct 18 21:15
    Arhell review_requested #18956
  • Oct 18 21:15
    Arhell ready_for_review #18956
matrixbot
@matrixbot
shurik2k5 try don't use plain sql code
matrixbot
@matrixbot
shurik2k5 like this
class m190801_122415_create_actions_table extends Migration
{
    private $_tableName;

    public function init()
    {
        parent::init();
        $this->_tableName = "{{%actions}}";
    }

    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
        }

        $this->createTable($this->_tableName, [
            'id' => $this->bigPrimaryKey(),
            'consumer' => $this->bigInteger(20)->notNull()->defaultValue(-1)->comment('Optional ID of the consumer that accessed the endpoint'),
            'date' => $this->dateTime(),
            'method' => $this->string(8)->notNull(),
            'endpoint' => $this->text()->notNull()->comment('query string on the request.'),
            'query' => $this->text()->notNull()->comment('IP Address used to access the page')
        ], $tableOptions);

        $tableName = str_replace('{{%', '', str_replace("}}", '', $this->_tableName));

        $this->createIndex('{{%idx-' . $tableName . '-consumer}}', $this->_tableName, 'consumer');
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable($this->_tableName);
    }
}
matrixbot
@matrixbot
shurik2k5 ActiveRecord base class has some magic get/set method for operate with model attributes.
You code can be shortened using features ActiveRecord base class
use yii\db\ActiveRecord;

/**
 * Class ActionLog
 *
 * @property int $id
 * @property int $consumer
 * @property string $date
 * @property string $method
 * @property string $endpoint
 * @property string $query
 * @property string $address
 */
class ActionLog extends ActiveRecord
{
    /**
     * @inheritDoc
     */
    public static function tableName()
    {
        return '{{%actions}}';
    }

    /** Creates a new instance of the action log */
    public static function create(): ActionLog
    {
        $log = new static();
        $log->consumer = -1;          //TODO: Finish Consumer
        $log->date = (new \DateTime('now', new \DateTimeZone('UTC')))->format('Y-m-d H:i:s');
        $log->method = \Yii::$app->request->getMethod();
        $log->endpoint = \Yii::$app->request->getPathInfo();
        $log->query = \Yii::$app->request->getQueryString();
        $log->address = \Yii::$app->request->getUserIP();
        return $log;
    }

    /**
     * @return int
     */
    public function getConsumerID(): int
    {
        return $this->consumer;
    }

    /**
     * @return string
     */
    public function getFullEndpoint(): string
    {
        return $this->method . ": " . $this->endpoint . "?" . $this->query;
    }

    /**
     * @inheritDoc
     */
    public function rules()
    {
        return [
            ['consumer', 'integer'],
            [['date', 'method', 'endpoint', 'query', 'address'], 'string'],
        ];
    }
}
shurik2k5 try to use phpDocs blocks and psr-2 coding style
Lachee
@Lachee
yeah, the main reason I did it the way I did is that I have a extension on VSCode that does type hinting really well
so I was trying to get it to work with yii. Since ActiveRecord uses magic to get the fields, its not able to type hint these values.
well, not just type hint actually.
its able to tell me what the members of the class are too
as a work around, I have just resulted in using getter functions
matrixbot
@matrixbot
shurik2k5 see in my code phpDocs block before class - it helps IDE to operate with 'virtual' attributes
Lachee
@Lachee
oh i see
Muhd Danish
@unsolvedru
image.png
Hi, I'm tryna use authclient, everything went good until after google account select
image.png
inside SiteController.php
oh wait is this the correct place to ask
anjandas0211
@anjandas0211
I want to integrate a yii2 extension in yii2(humhub). How I do it?
Lachee
@Lachee
I have the following REST function
public function actionView($id, $period = null, $type = null)
and my ID is a compound key, ABN and Invoice Number
so when I am making a request, I would normally do api/transaction/abn,invoice
however, the invoice number contains -
which seem to break the routing.
api/11111111138,0242 works
api/11111111138,024-2 doesn't
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