elvandar/ec-bundle

一个简化与外部网站通信的捆绑包

安装: 6

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

1.0 2018-11-15 11:21 UTC

This package is auto-updated.

Last update: 2024-09-16 03:32:13 UTC


README

一个小的捆绑包,用于帮助在symfony项目中使用外部URL。

目标是集中管理所有路由在一个配置文件中,并提供使用它们的函数。

安装

打开命令行,进入你的项目目录并执行

$ composer require <package-name>

如何使用捆绑包

elvandar_ec.yml 中,你可以配置你的网站和路由

    site:
        routes:
            name: 'http://path/to/your/site'

该文件组织在 sites 中。每个 site 代表 routes 列表下的URL分组。

配置示例

    your_first_site:
        routes:
            home: 'http://first-site/'
            description: 'http://first-site/description'
            contact: 'http://first-site/contact'
    your_second_site:
        routes:
            home: 'http://second-site/'
            contact: 'http://second-site/contact'
            blog: 'http://second-site/blog'
            
    The name of your site: # the name you want to give to your site
        routes:            # a list of the site routes
            Name: 'URL'    # name of the route : url of the route

使用服务

你现在可以使用 Externals 服务来检索

    $externals = $this->container->get('ec');
    
    $externals->getRoute('contact', 'your_second_site');

或重定向到所需的路由

    $externals = $this->container->get('ec');

    $externals->redirectToExternal('description', 'your_first_site');

redirectToEcternalgetRoute 方法遵循相同的参数规则

1 - 第一个参数

第一个参数是你的路由名称。

例如,在示例配置中,http://second-site/blog 的名称是 blog

此参数是必需的。

2 - 第二个参数

第二个参数是网站的名称。它不是必需的,但如果多个路由有相同的名称,则需要它。

例如,对于 blog 路由,第二个参数不是必需的,但对于 homecontact 路由则是必需的。