skeeks\cms\helpers\UrlHelper::constructCurrent PHP Method

constructCurrent() public static method

public static constructCurrent ( ) : static
return static
    public static function constructCurrent()
    {
        $route = [];
        if (!\Yii::$app->controller->module instanceof Application) {
            $route[] = \Yii::$app->controller->module->id;
        }
        $route[] = \Yii::$app->controller->id;
        $route[] = \Yii::$app->controller->action->id;
        $url = new static("/" . implode('/', $route), \Yii::$app->request->getQueryParams());
        if (\Yii::$app->admin->requestIsAdmin) {
            $url->enableAdmin();
        }
        return $url;
    }

Usage Example

 public function create()
 {
     $rr = new RequestResponse();
     $modelClass = $this->modelClassName;
     $model = new $modelClass();
     $model->loadDefaultValues();
     if ($post = \Yii::$app->request->post()) {
         $model->load($post);
     }
     $handler = $model->handler;
     if ($handler) {
         if ($post = \Yii::$app->request->post()) {
             $handler->load($post);
         }
     }
     if ($rr->isRequestPjaxPost()) {
         if (!\Yii::$app->request->post($this->notSubmitParam)) {
             $model->component_settings = $handler->toArray();
             $handler->load(\Yii::$app->request->post());
             if ($model->load(\Yii::$app->request->post()) && $model->validate() && $handler->validate()) {
                 $model->save();
                 \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/cms', 'Saved'));
                 return $this->redirect(UrlHelper::constructCurrent()->setCurrentRef()->enableAdmin()->setRoute($this->modelDefaultAction)->normalizeCurrentRoute()->addData([$this->requestPkParamName => $model->{$this->modelPkAttribute}])->toString());
             } else {
                 \Yii::error(Json::encode($model->errors), self::className());
                 \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/cms', 'Could not save'));
             }
         }
     }
     return $this->render('_form', ['model' => $model, 'handler' => $handler]);
 }
All Usage Examples Of skeeks\cms\helpers\UrlHelper::constructCurrent