Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8214465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:28:21+00:00 2026-06-07T11:28:21+00:00

Using the Gedmo Sluggable behavior in Symfony2, I need to know if there is

  • 0

Using the Gedmo Sluggable behavior in Symfony2, I need to know if there is a way to allow both slashes (/) and dashes (-) as word separators. In other words, one specific separator as usual, but leaving alone the other specific special character so it is ignored. I want to do something like this as a slug:

products/some-product

This allows me to use slugs in the URL that are categorized via the slash and separate the spaces via the dash. But, for instance, if the separator is “/”, the “-” will be replaced as well instead of left alone.

I’ve looked through the related Sluggable class code (Urlizer) and see a lot of regex going on, but I’m not sure where I should override to allow slashed and/or dashes to NOT be substituted along with everything else.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:28:22+00:00Added an answer on June 7, 2026 at 11:28 am

    Turns out you can accomplish this by creating your own class that extends Urlizer, then setting it as the callable for the listener instead of Gedmo’s class.

    When using STOF doctrine extensions, a sluggable listener is created as a service, but it is set as private so you can’t normally access. So you must first create an alias to this listener in your own config:

    services:
    
        sluggable.listener:
            alias: stof_doctrine_extensions.listener.sluggable
    

    You must then create your class. There is a setter called setTransliterator() that you can use to call your own transliterator, which you can then use to inject what you need to modify the slugging process. The function postProccessText() is what you really want to modify, the transliterate() function is just what is callable:

    namespace My\Bundle\Util;
    
    use Gedmo\Sluggable\Util\Urlizer as BaseUrlizer;
    
    class Urlizer extends BaseUrlizer
    {
        public static function transliterate($text, $separator = '-')
        {
            // copy the code from the parent here
        }
    
        private static function postProcessText($text, $separator)
        {
            // copy code from parent, but modify the following part:
    
            $text = strtolower(preg_replace('/[^A-Z^a-z^0-9^\/]+/', $separator,
                               preg_replace('/([a-z\d])([A-Z])/', '\1_\2',
                               preg_replace('/([A-Z]+)([A-Z][a-z])/', '\1_\2',
                               preg_replace('/::/', '/', $text)))));
        }
    }
    

    The regular expressions of postProcessText() are what you want to modify to your liking. After that, you must make your function the callable right before you persist, and you’re good to go:

    // custom transliterator
    $listener = $this->get('sluggable.listener');
    $listener->setTransliterator(array('My\Bundle\Util\Urlizer', 'transliterate'));
    $em->flush();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Microsoft SQL Server 2005, is there any way to see when a table
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using SQL Server 2008 R2 we are looking for a way to select the
Using android 2.3.3, I have a background Service which has a socket connection. There's
Using NSDateComponents I know how to get the day component, but this gives me
using a binary search tree I need to add to a vector all int
(Using MVC 2) From inside my controller action, I need to display the url:
Using gcc and ld on x86_64 linux I need to link against a newer
using VB.Net2010 I need to call a C# DLL The problem I have is
Using online interfaces to a version control system is a nice way to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.