当前位置: 首页>>代码示例>>PHP>>正文


PHP modX::toQueryString方法代码示例

本文整理汇总了PHP中modX::toQueryString方法的典型用法代码示例。如果您正苦于以下问题:PHP modX::toQueryString方法的具体用法?PHP modX::toQueryString怎么用?PHP modX::toQueryString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在modX的用法示例。


在下文中一共展示了modX::toQueryString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: makeUrl

    /**
     * Generates a URL representing a specified resource in this context.
     *
     * Note that if this method is called from a context other than the one
     * initialized for the modX instance, and the scheme is not specified, an
     * empty string, or abs, the method will force the scheme to full.
     *
     * @access public
     * @param integer $id The id of a resource.
     * @param string $args A query string to append to the generated URL.
     * @param mixed $scheme The scheme indicates in what format the URL is generated.<br>
     * <pre>
     *      -1 : (default value) URL is relative to site_url
     *       0 : see http
     *       1 : see https
     *    full : URL is absolute, prepended with site_url from config
     *     abs : URL is absolute, prepended with base_url from config
     *    http : URL is absolute, forced to http scheme
     *   https : URL is absolute, forced to https scheme
     * </pre>
     * @return string The URL for the resource.
     */
    public function makeUrl($id, $args = '', $scheme = -1) {
        $url = '';
        $found = false;
        if ($id= intval($id)) {
            if (is_object($this->xpdo->context) && $this->get('key') !== $this->xpdo->context->get('key')) {
                $config = array_merge($this->xpdo->_systemConfig, $this->config, $this->xpdo->_userConfig);
                if ($scheme === -1 || $scheme === '' || strpos($scheme, 'abs') !== false) {
                    $scheme= 'full';
                }
            } else {
                $config = $this->xpdo->config;
            }

            if ($config['friendly_urls'] == 1) {
                if ($id == $config['site_start']) {
                    $alias= ($scheme === '' || $scheme === -1) ? $config['base_url'] : '';
                    $found= true;
                } else {
                    $alias= array_search($id, $this->aliasMap);
                    if (!$alias) {
                        $alias= '';
                        $this->xpdo->log(xPDO::LOG_LEVEL_WARN, '`' . $id . '` was requested but no alias was located.');
                    } else {
                        $found= true;
                    }
                }
            } elseif (isset($this->resourceListing["{$id}"])) {
                $found= true;
            }

            if ($found) {
                if (is_array($args)) {
                    $args = modX::toQueryString($args);
                }
                if ($args != '' && $config['friendly_urls'] == 1) {
                    /* add ? to $args if missing */
                    $c= substr($args, 0, 1);
                    if ($c == '&') {
                        $args= '?' . substr($args, 1);
                    } elseif ($c != '?') {
                        $args= '?' . $args;
                    }
                }
                elseif ($args != '') {
                    /* add & to $args if missing */
                    $c= substr($args, 0, 1);
                    if ($c == '?')
                        $args= '&' . substr($args, 1);
                    elseif ($c != '&') $args= '&' . $args;
                }

                if ($config['friendly_urls'] == 1) {
                    $url= $alias . $args;
                } else {
                    $url= $config['request_controller'] . '?' . $config['request_param_id'] . '=' . $id . $args;
                }

                $host= '';
                if ($scheme !== -1 && $scheme !== '') {
                    if ($scheme === 1 || $scheme === 0) {
                        $https_port= $this->getOption('https_port',$config,443);
                        $isSecure= ($_SERVER['SERVER_PORT'] == $https_port || (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'])=='on')) ? 1 : 0;
                        if ($scheme != $isSecure) {
                            $scheme = $isSecure ? 'http' : 'https';
                        }
                    }
                    switch ($scheme) {
                        case 'full':
                            $host= $config['site_url'];
                            break;
                        case 'abs':
                        case 'absolute':
                            $host= $config['base_url'];
                            break;
                        case 'https':
                        case 'http':
                            $host= $scheme . '://' . $config['http_host'] . $config['base_url'];
                            break;
//.........这里部分代码省略.........
开发者ID:ncrossland,项目名称:revolution,代码行数:101,代码来源:modcontext.class.php

示例2: makeUrl

 /**
  * @param $id
  * @param array $options
  * @param array $args
  *
  * @return mixed|string
  */
 public function makeUrl($id, $options = array(), $args = array())
 {
     $scheme = !empty($options['scheme']) ? $options['scheme'] : $this->config['scheme'];
     if (strtolower($scheme) == 'uri' && !empty($options['uri'])) {
         $url = $options['uri'];
         if (!empty($args)) {
             if (is_array($args)) {
                 $args = rtrim(modX::toQueryString($args), '?&');
             }
             $url .= strpos($url, '?') !== false ? '&' : '?';
             $url .= ltrim(trim($args), '?&');
         }
     } else {
         if (!empty($options['context_key'])) {
             $context = $options['context_key'];
         } elseif (!empty($options['context'])) {
             $context = $options['context'];
         } else {
             $context = '';
         }
         if (strtolower($scheme) == 'uri') {
             $scheme = -1;
         }
         $url = $this->modx->makeUrl($id, $context, $args, $scheme, $options);
     }
     return $url;
 }
开发者ID:MobiTeam,项目名称:mirfoto,代码行数:34,代码来源:pdotools.class.php

示例3: testToQueryString

 /**
  * @param array $parameters
  * @param string $expected
  * @dataProvider providerToQueryString
  */
 public function testToQueryString(array $parameters, $expected)
 {
     $result = modX::toQueryString($parameters);
     $this->assertEquals($expected, $result);
 }
开发者ID:kundius,项目名称:revolution,代码行数:10,代码来源:modXTest.php

示例4: makeUrl

 /**
  * Generates a URL representing a specified resource in this context.
  *
  * Note that if this method is called from a context other than the one
  * initialized for the modX instance, and the scheme is not specified, an
  * empty string, or abs, the method will force the scheme to full.
  *
  * @access public
  * @param integer $id The id of a resource.
  * @param string $args A query string to append to the generated URL.
  * @param mixed $scheme The scheme indicates in what format the URL is generated.<br>
  * <pre>
  *      -1 : (default value) URL is relative to site_url
  *       0 : see http
  *       1 : see https
  *    full : URL is absolute, prepended with site_url from config
  *     abs : URL is absolute, prepended with base_url from config
  *    http : URL is absolute, forced to http scheme
  *   https : URL is absolute, forced to https scheme
  * </pre>
  * @param array $options An array of options for generating the Resource URL.
  * @return string The URL for the resource.
  */
 public function makeUrl($id, $args = '', $scheme = -1, array $options = array())
 {
     $url = '';
     $found = false;
     if ($id = intval($id)) {
         if ($this->config === null) {
             $this->prepare();
         }
         if (is_object($this->xpdo->context) && $this->get('key') !== $this->xpdo->context->get('key')) {
             $config = array_merge($this->xpdo->_systemConfig, $this->config, $this->xpdo->_userConfig, $options);
             if ($scheme === -1 || $scheme === '' || strpos($scheme, 'abs') !== false) {
                 $scheme = 'full';
             }
         } else {
             $config = array_merge($this->xpdo->config, $options);
         }
         if ($config['friendly_urls'] == 1) {
             if ((int) $id === (int) $config['site_start']) {
                 $alias = $scheme === '' || $scheme === -1 ? $config['base_url'] : '';
                 $found = true;
             } else {
                 $alias = $this->getResourceURI($id);
                 if (!$alias) {
                     $alias = '';
                     $this->xpdo->log(xPDO::LOG_LEVEL_WARN, '`' . $id . '` was requested but no alias was located.');
                 } else {
                     $found = true;
                 }
             }
         } elseif (array_keys(array((string) $id), $this->resourceMap, true) !== false) {
             $found = true;
         }
         if ($found) {
             $target = null;
             if (isset($config['use_weblink_target']) && !empty($config['use_weblink_target'])) {
                 if (array_key_exists($id, $this->webLinkMap)) {
                     $target = $this->webLinkMap[$id];
                     if (!empty($target)) {
                         $alias = $target;
                     }
                 }
             }
             $targetHasQS = empty($config['friendly_urls']) || strpos($alias, '?') !== false;
             if (is_array($args)) {
                 $args = modX::toQueryString($args);
             }
             if ($args != '') {
                 if (!$targetHasQS) {
                     /* add ? to $args if missing */
                     $c = substr($args, 0, 1);
                     if ($c == '&') {
                         $args = '?' . substr($args, 1);
                     } elseif ($c != '?') {
                         $args = '?' . $args;
                     }
                 } elseif ($args != '') {
                     /* add & to $args if missing */
                     $c = substr($args, 0, 1);
                     if ($c == '?') {
                         $args = '&' . substr($args, 1);
                     } elseif ($c != '&') {
                         $args = '&' . $args;
                     }
                 }
             }
             if ($config['friendly_urls'] == 1 || $target !== null) {
                 $url = $alias . $args;
             } else {
                 $url = $config['request_controller'] . '?' . $config['request_param_id'] . '=' . $id . $args;
             }
             $host = '';
             if ($target === null && $scheme !== -1 && $scheme !== '') {
                 if ($scheme === 1 || $scheme === 0) {
                     $https_port = $this->getOption('https_port', $config, 443);
                     $isSecure = $_SERVER['SERVER_PORT'] == $https_port || isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 1 : 0;
                     if ($scheme != $isSecure) {
                         $scheme = $isSecure ? 'http' : 'https';
//.........这里部分代码省略.........
开发者ID:raadhuis,项目名称:modx-basic,代码行数:101,代码来源:modcontext.class.php


注:本文中的modX::toQueryString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。