Joomla 重写组件中的管线类

Joomla 重写组件中的管线类,joomla,url-routing,Joomla,Url Routing,如何覆盖组件中的类路由。我需要这个来重写url的方式,我需要它。我尝试创建文件route.php并扩展route类。但不能在视图中调用它。我说的是这个文件: <?php /** * Joomla! Content Management System * * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Pub

如何覆盖组件中的
类路由
。我需要这个来重写url的方式,我需要它。我尝试创建文件
route.php
并扩展
route
类。但不能在视图中调用它。我说的是这个文件:

<?php
/**
 * Joomla! Content Management System
 *
 * @copyright  Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\CMS\Router;

defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;

/**
 * Route handling class
 *
 * @since  11.1
 */
class Route
{
    /**
     * The route object so we don't have to keep fetching it.
     *
     * @var    Router
     * @since  12.2
     */
    private static $_router = null;

    /**
     * Translates an internal Joomla URL to a humanly readable URL.
     *
     * @param   string   $url    Absolute or Relative URI to Joomla resource.
     * @param   boolean  $xhtml  Replace & by &amp; for XML compliance.
     * @param   integer  $ssl    Secure state for the resolved URI.
     *                             0: (default) No change, use the protocol currently used in the request
     *                             1: Make URI secure using global secure site URI.
     *                             2: Make URI unsecure using the global unsecure site URI.
     *
     * @return string The translated humanly readable URL.
     *
     * @since   11.1
     */
    public static function _($url, $xhtml = true, $ssl = null)
    {
        if (!self::$_router)
        {
            // Get the router.
            $app = Factory::getApplication();
            self::$_router = $app::getRouter();

            // Make sure that we have our router
            if (!self::$_router)
            {
                return;
            }
        }

        if (!is_array($url) && (strpos($url, '&') !== 0) && (strpos($url, 'index.php') !== 0))
        {
            return $url;
        }

        // Build route.
        $uri = self::$_router->build($url);

        $scheme = array('path', 'query', 'fragment');

        /*
         * Get the secure/unsecure URLs.
         *
         * If the first 5 characters of the BASE are 'https', then we are on an ssl connection over
         * https and need to set our secure URL to the current request URL, if not, and the scheme is
         * 'http', then we need to do a quick string manipulation to switch schemes.
         */
        if ((int) $ssl || $uri->isSsl())
        {
            static $host_port;

            if (!is_array($host_port))
            {
                $uri2 = Uri::getInstance();
                $host_port = array($uri2->getHost(), $uri2->getPort());
            }

            // Determine which scheme we want.
            $uri->setScheme(((int) $ssl === 1 || $uri->isSsl()) ? 'https' : 'http');
            $uri->setHost($host_port[0]);
            $uri->setPort($host_port[1]);
            $scheme = array_merge($scheme, array('host', 'port', 'scheme'));
        }

        $url = $uri->toString($scheme);

        // Replace spaces.
        $url = preg_replace('/\s/u', '%20', $url);

        if ($xhtml)
        {
            $url = htmlspecialchars($url, ENT_COMPAT, 'UTF-8');
        }

        return $url;
    }
}

对于URL重写,您可以使用router.php文件以您想要的方式重写组件的URL。它可以扩展
jcomponentroterbase
jcomponentroterview
。然后您可以使用
构建
解析
函数。我不知道在这些方法中可以在哪里重写我的url。他们正在返回一些查询和变量。其中vars似乎是带有固定键的数组-任务、视图、id。好的,那么你能解释一下你到底想在URL中更改什么吗?谢谢,我想把汽车的细节写进去。例如,从db表中获取数据并构造:mysite.com/carmake-caryear-carmodelys组件中的
router.php
文件的用途。您可以从视图或任何位置创建一个非sef URL,然后在
router.php
文件中,您只需操作传入请求并从中创建一个sef URL。对于URL重写,您可以使用router.php文件以您想要的方式重写组件的URL。它可以扩展
jcomponentroterbase
jcomponentroterview
。然后您可以使用
构建
解析
函数。我不知道在这些方法中可以在哪里重写我的url。他们正在返回一些查询和变量。其中vars似乎是带有固定键的数组-任务、视图、id。好的,那么你能解释一下你到底想在URL中更改什么吗?谢谢,我想把汽车的细节写进去。例如,从db表中获取数据并构造:mysite.com/carmake-caryear-carmodelys组件中的
router.php
文件的用途。您可以从视图或任意位置创建一个非sef URL,然后在
router.php
文件中,您只需操作传入的请求并从中创建一个sef URL。