手动生成教条 [英] Generating doctrine slugs manually

查看:152
本文介绍了手动生成教条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Symfony2项目中使用了可耻的行为,但是现在我想根据不同的文本(当前标题,旧标题,表单输入的用户文本),为一个页面做出许多s),并保持它在另一个表。我的问题是 - 如何手动使用任何文本的原则扩展?我找不到任何地方完美将是这样的:

  / *小心 - 这不是一个真正的工作代码! * / 
$ sluggable = new DoctrineSluggable();
$ slug = $ sluggable-> generate('我自己的文本!');
echo $ slug; //我自己的文本


解决方案

查找原则代码用于在这里生成一个插件: l3pp4rd / DoctrineExtensions 。玩这个课程可以做你想要的,但你可能需要创建自己的服务来实现一个容易的使用,你想要的。有关服务的更多详细信息,请参阅文档的服务容器部分。


I'm using sluggable behavior in my Symfony2 project, but now I would like to make many slugs for one page, based on different texts (current title, old title(s), users text from form input), and keep it in another table. And my question is - how to manually use doctrine extensions for any text? I can't find it anywhere. Perfect would be something like:

/* careful - it's not a real, working code! */
$sluggable = new DoctrineSluggable();
$slug = $sluggable->generate('My own text!');
echo $slug; // my-own-text

解决方案

Find the doctrine code for generating a slug here: l3pp4rd/DoctrineExtensions. Playing around with that class could do as you desire but you will probable need to create your own service to implement an easy use as you want. See the Service Container section of the docs for more details about services.

这篇关于手动生成教条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆