Beispiel #1
0
 static function url($url, $parmas = null)
 {
     $arr[] = $url;
     if (is_array($parmas)) {
         $arr = array_merge($arr, $parmas);
     }
     return \yii\helpers\Html::url($arr);
 }
 /**
  * Redirects the browser to the specified URL.
  * This method is a shortcut to [[Response::redirect()]].
  *
  * You can use it in an action by returning the [[Response]] directly:
  *
  * ```php
  * // stop executing this action and redirect to login page
  * return $this->redirect(['login']);
  * ```
  *
  * @param string|array $url the URL to be redirected to. This can be in one of the following formats:
  *
  * - a string representing a URL (e.g. "http://example.com")
  * - a string representing a URL alias (e.g. "@example.com")
  * - an array in the format of `[$route, ...name-value pairs...]` (e.g. `['site/index', 'ref' => 1]`)
  *   [[Html::url()]] will be used to convert the array into a URL.
  *
  * Any relative URL will be converted into an absolute one by prepending it with the host info
  * of the current request.
  *
  * @param integer $statusCode the HTTP status code. Defaults to 302.
  * See <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>
  * for details about HTTP status code
  * @return Response the current response object
  */
 public function redirect($url, $statusCode = 302)
 {
     return Yii::$app->getResponse()->redirect(Html::url($url), $statusCode);
 }
 /**
  * Redirects the browser to the specified URL.
  *
  * This method adds a "Location" header to the current response. Note that it does not send out
  * the header until [[send()]] is called. In a controller action you may use this method as follows:
  *
  * ~~~
  * return Yii::$app->getResponse()->redirect($url);
  * ~~~
  *
  * In other places, if you want to send out the "Location" header immediately, you should use
  * the following code:
  *
  * ~~~
  * Yii::$app->getResponse()->redirect($url)->send();
  * return;
  * ~~~
  *
  * In AJAX mode, this normally will not work as expected unless there are some
  * client-side JavaScript code handling the redirection. To help achieve this goal,
  * this method will send out a "X-Redirect" header instead of "Location".
  *
  * If you use the "yii" JavaScript module, it will handle the AJAX redirection as
  * described above. Otherwise, you should write the following JavaScript code to
  * handle the redirection:
  *
  * ~~~
  * $document.ajaxComplete(function (event, xhr, settings) {
  *     var url = xhr.getResponseHeader('X-Redirect');
  *     if (url) {
  *         window.location = url;
  *     }
  * });
  * ~~~
  *
  * @param string|array $url the URL to be redirected to. This can be in one of the following formats:
  *
  * - a string representing a URL (e.g. "http://example.com")
  * - a string representing a URL alias (e.g. "@example.com")
  * - an array in the format of `[$route, ...name-value pairs...]` (e.g. `['site/index', 'ref' => 1]`).
  *   Note that the route is with respect to the whole application, instead of relative to a controller or module.
  *   [[Html::url()]] will be used to convert the array into a URL.
  *
  * Any relative URL will be converted into an absolute one by prepending it with the host info
  * of the current request.
  *
  * @param integer $statusCode the HTTP status code. Defaults to 302.
  * See <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>
  * for details about HTTP status code
  * @return static the response object itself
  */
 public function redirect($url, $statusCode = 302)
 {
     if (is_array($url) && isset($url[0])) {
         // ensure the route is absolute
         $url[0] = '/' . ltrim($url[0], '/');
     }
     $url = Html::url($url);
     if (strpos($url, '/') === 0 && strpos($url, '//') !== 0) {
         $url = Yii::$app->getRequest()->getHostInfo() . $url;
     }
     if (Yii::$app->getRequest()->getIsAjax()) {
         $this->getHeaders()->set('X-Redirect', $url);
     } else {
         $this->getHeaders()->set('Location', $url);
     }
     $this->setStatusCode($statusCode);
     return $this;
 }
 /**
  * Returns the options for the captcha JS widget.
  * @return array the options
  */
 protected function getClientOptions()
 {
     $options = ['refreshUrl' => Html::url(['/' . $this->captchaAction, CaptchaAction::REFRESH_GET_VAR => 1]), 'hashKey' => "yiiCaptcha/{$this->captchaAction}"];
     return $options;
 }
 /**
  * Returns the options for the form JS widget.
  * @return array the options
  */
 protected function getClientOptions()
 {
     $options = ['errorSummary' => '.' . $this->errorSummaryCssClass, 'validateOnSubmit' => $this->validateOnSubmit, 'errorCssClass' => $this->errorCssClass, 'successCssClass' => $this->successCssClass, 'validatingCssClass' => $this->validatingCssClass, 'ajaxVar' => $this->ajaxVar];
     if ($this->validationUrl !== null) {
         $options['validationUrl'] = Html::url($this->validationUrl);
     }
     foreach (['beforeSubmit', 'beforeValidate', 'afterValidate'] as $name) {
         if (($value = $this->{$name}) !== null) {
             $options[$name] = $value instanceof JsExpression ? $value : new JsExpression($value);
         }
     }
     return $options;
 }
Beispiel #6
0
 /**
  * Redirects to url. If the authorization dialog opened in the popup window,
  * it will be closed instead of redirect. Set $jsRedirect=true if you want
  * to redirect anyway.
  *
  * @param mixed $url url to redirect. Can be route or normal url. See {@link CHtml::normalizeUrl}.
  * @param boolean $jsRedirect whether to use redirect while popup window is used. Defaults to true.
  * @param array $params
  */
 public function redirect($url, $jsRedirect = true, $params = array())
 {
     /** @var RedirectWidget $widget */
     $widget = Yii::createObject(array('class' => $this->redirectWidget, 'url' => Html::url($url), 'redirect' => $jsRedirect, 'params' => $params));
     ob_start();
     $widget->run();
     $output = ob_get_clean();
     $response = Yii::$app->getResponse();
     $response->content = $output;
     $response->send();
     exit;
 }
 /**
  * Renders the content of a menu item.
  * Note that the container and the sub-menus are not rendered here.
  * @param array $item the menu item to be rendered. Please refer to [[items]] to see what data might be in the item.
  * @return string the rendering result
  */
 protected function renderItem($item)
 {
     if (isset($item['url'])) {
         $template = ArrayHelper::getValue($item, 'template', $this->linkTemplate);
         return strtr($template, ['{url}' => Html::url($item['url']), '{label}' => $item['label']]);
     } else {
         $template = ArrayHelper::getValue($item, 'template', $this->labelTemplate);
         return strtr($template, ['{label}' => $item['label']]);
     }
 }
 /**
  * Returns the options for the grid view JS widget.
  * @return array the options
  */
 protected function getClientOptions()
 {
     $filterUrl = isset($this->filterUrl) ? $this->filterUrl : [Yii::$app->controller->action->id];
     $id = $this->filterRowOptions['id'];
     $filterSelector = "#{$id} input, #{$id} select";
     if (isset($this->filterSelector)) {
         $filterSelector .= ', ' . $this->filterSelector;
     }
     return ['filterUrl' => Html::url($filterUrl), 'filterSelector' => $filterSelector];
 }
Beispiel #9
0
 /**
  * Renders a widget's item.
  * @param string|array $item the item to render.
  * @return string the rendering result.
  * @throws InvalidConfigException
  */
 public function renderItem($item)
 {
     if (is_string($item)) {
         return $item;
     }
     if (!isset($item['label'])) {
         throw new InvalidConfigException("The 'label' option is required.");
     }
     $label = $this->encodeLabels ? Html::encode($item['label']) : $item['label'];
     $options = ArrayHelper::getValue($item, 'options', []);
     $items = ArrayHelper::getValue($item, 'items');
     $url = Html::url(ArrayHelper::getValue($item, 'url', '#'));
     $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
     $showCaret = ArrayHelper::getValue($item, 'showCaret', true);
     $caretHtml = ArrayHelper::getValue($item, 'caretHtml', '');
     $dropdownMenuOptions = ArrayHelper::getValue($item, 'dropdownMenuOptions', []);
     if (isset($item['active'])) {
         $active = ArrayHelper::remove($item, 'active', false);
     } else {
         $active = $this->isItemActive($item);
     }
     if ($active) {
         Html::addCssClass($options, 'active');
     }
     if ($items !== null) {
         $linkOptions['data-toggle'] = 'dropdown';
         Html::addCssClass($options, 'dropdown');
         Html::addCssClass($linkOptions, 'dropdown-toggle');
         if ($showCaret) {
             if ($caretHtml) {
                 $label .= ' ' . $caretHtml;
             } else {
                 $label .= ' ' . Html::tag('b', '', ['class' => 'caret']);
             }
         }
         if (is_array($items)) {
             $items = Dropdown::widget(['items' => $items, 'encodeLabels' => $this->encodeLabels, 'clientOptions' => false, 'view' => $this->getView(), 'options' => $dropdownMenuOptions]);
         }
     }
     return Html::tag('li', Html::a($label, $url, $linkOptions) . $items, $options);
 }