didweb/slug

创建友好的URL缩略名

安装: 24

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

2.0.2 2014-05-25 00:00 UTC

This package is not auto-updated.

Last update: 2024-09-23 11:54:20 UTC


README

这是一个创建缩略名的简单脚本。

安装。

composer.json 文件中安装组件...

"require": {
        ....
        "didweb/slug": "2.*"
        ....
     }

app/AppKernel.php 文件中添加...

$bundles = array(
    ...
    new Slug\SlugBundle\SlugSlugBundle(),
    ....
    );

在配置文件:app/config/config.yml...

imports:
    - { resource: "@SlugSlugBundle/Resources/config/services.yml" }

使用示例

如果您想在控制器中使用了这个服务,可以按照以下方式...

    $text = 'Text Besipiel: Á è ñ P % --o Wç ü ö ä';
    $slug = $this->get('didweb_slug.accion');
    $res = $slug->clean($texto);

默认代码使用破折号 - 作为分隔符。您可以通过将分隔符作为参数传递给 clean 函数来更改您想要的分隔符。分隔符是可选参数,所以如果没有指定,默认使用破折号 -

以下是一个使用下划线 _ 作为分隔符的示例

    $text = 'Text Besipiel: Á è ñ P % --o Wç ';
    $slug = $this->get('didweb_slug.accion');
    $res = $slug->clean($text,'_');

🇬🇧 Slug

这是一个创建Slugs的小脚本。

安装

使用composer安装,将以下内容放入 composer.json 文件...

"require": {
        ....
        "didweb/slug": "2.*"
        ....
     }

app/AppKernel.php 文件中添加...

$bundles = array(
    ...
    new Slug\SlugBundle\SlugSlugBundle(),
    ....
    );

在配置文件:app/config/config.yml 中这样导入服务

imports:
    - { resource: "@SlugSlugBundle/Resources/config/services.yml" }

使用示例

当您想在控制器中使用该服务时,可以按以下方式使用...

    $text = 'Texto de ejemplo: Á è ñ P % --o Wç ';
    $slug = $this->get('didweb_slug.accion');
    $resultado = $slug->clean($text);

默认代码使用破折号 - 作为分隔符。您可以通过将分隔符作为参数传递给 cleaning 函数来更改您想要的分隔符。分隔符是可选参数,所以如果没有指定,默认使用破折号 -

以下是一个使用破折号 _ 修改分隔符的示例

   $texto = 'Texto de ejemplo: Á è ñ P % --o Wç ';
   $slug = $this->get('didweb_slug.accion');
   $resultado = $slug->clean($texto,'_');

🇪🇸 Slug

这是一个创建Slugs的小脚本。

安装

使用composer安装,将以下内容放入 composer.json 文件...

"require": {
        ....
        "didweb/slug": "2.*"
        ....
     }

app/AppKernel.php 文件中添加...

$bundles = array(
    ...
    new Slug\SlugBundle\SlugSlugBundle(),
    ....
    );

在配置文件:app/config/config.yml 中这样导入服务

imports:
    - { resource: "@SlugSlugBundle/Resources/config/services.yml" }

使用示例

当您想在控制器中使用该服务时,可以按以下方式使用...


    $text = 'Texto de ejemplo: Á è ñ P % --o Wç ';
    $slug = $this->get('didweb_slug.accion');
    $resultado = $slug->clean($text);

默认代码使用破折号 - 作为分隔符。您可以通过将分隔符作为参数传递给 clean 函数来更改您想要的分隔符。分隔符是可选参数,所以如果没有指定,默认使用破折号 -

以下是一个使用下划线 _ 修改分隔符的示例

    $texto = 'Texto de ejemplo: Á è ñ P % --o Wç ';
    $slug = $this->get('didweb_slug.accion');
    $resultado = $slug->clean($texto,'_');