我一直在寻找一种内置的方法来urlize / slugify一个字符串,而不是复制一个在google上找到的一个straard。
因此我发现了这个:http://sourcecookbook.com/en/recipes/59/call-the-slugify-urlize-function-from-doctrine,引用了这个Doctrine Class http://www.tig12.net/downloads/apidocs/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Doctrine_Inflector.class.html,方法urlize()
正是我正在寻找的。 p>
但是,在我的Symfony 2的Doctrine Bundle中,\vendor\doctrine\common\lib\Doctrine\Common\Util
我的Inflector类非常空。
这种urlize()
方法发生了什么变化?我需要重新编码吗?
答案 0 :(得分:2)
其中包含来自Doctrine1的urlize函数的https://github.com/Behat/Transliterator
这是从学说1.2.3中取得的部分 Doctrine变换器具有用于调整文本的静态方法
你可以composer require behat/transliterator
并有一个HelperClass扩展Behat\Transliterator
。
然后能够做到:MyStringHelper::urlize("isn't that great?")
答案 1 :(得分:1)
您正在查看的文件(Doctrine \ Common \ Util \ Inflector)应该由Doctrine在内部使用,以在表名(下划线分隔),属性名(camelCase)和类名(CamelCase)之间进行转换。
使用sluggable学说扩展可以实现您所寻求的目标。您可以使用stof/StofDoctrineExtensionsBundle轻松地将其集成到symfony2应用程序中。