Symfony1 Symfony西里尔语路由段塞

Symfony1 Symfony西里尔语路由段塞,symfony1,symfony-1.4,cyrillic,Symfony1,Symfony 1.4,Cyrillic,我对slagify路由参数有问题。我想将所有间隔和符号替换为-。当参数使用拉丁字母时,所有操作都有效,但若我尝试使用西里尔字母对参数进行slagify,则会出现错误 路由: catTests: url: /cat/:id/:name_slug class: sfDoctrineRoute options: { model: categories, type: object } param: { module: categories, a

我对slagify路由参数有问题。我想将所有间隔和符号替换为-。当参数使用拉丁字母时,所有操作都有效,但若我尝试使用西里尔字母对参数进行slagify,则会出现错误

路由:

 catTests:
      url:    /cat/:id/:name_slug
      class:   sfDoctrineRoute
      options: { model: categories, type: object }
      param: { module: categories, action: testsByCat }
      requirements:
        id: \d+
slug函数:

static public function slugify($text)
{
  // replace all non letters or digits by -
  $text = preg_replace('/\W+/', '-', $text);

  // trim and lowercase
  $text = strtolower(trim($text, '-'));

  return $text;
}

public function getNameSlug()
{
  $text= Category::slugify($this->getName());
  return $text;
}
例如: 我在数据库中有两个名字:

英语 Български език 通常,whitin函数url为:

英语+语言 Български+език 当我输入函数结果时:

英语 在西里尔文版本上,参数为空。 解析URL/cat/1//后,空模块和/或操作

我建议您使用slagify函数,而不是您自己的slagify函数,因为您使用的是原则

然后,替换您的函数,如:

public function getNameSlug()
{
  return Doctrine_Inflector::urlize($this->getName());
}
编辑:

事实上,即使在2.0版本中,条令似乎也不能很好地处理西里尔语。你得自己处理。我发现:

然后:

public function getNameSlug()
{
  $slug = Category::replaceCyrillic($this->getName());
  return Doctrine_Inflector::urlize($slug);
}
我建议您使用slagify函数,而不是您自己的slagify函数,因为您使用的是原则

然后,替换您的函数,如:

public function getNameSlug()
{
  return Doctrine_Inflector::urlize($this->getName());
}
编辑:

事实上,即使在2.0版本中,条令似乎也不能很好地处理西里尔语。你得自己处理。我发现:

然后:

public function getNameSlug()
{
  $slug = Category::replaceCyrillic($this->getName());
  return Doctrine_Inflector::urlize($slug);
}

你也可以在你的项目中修正这种行为。 多亏了symfony autoloader,它在插件启动之前预先设置了您的全局目录,您可以这样做:

mkdir lib/doctrine
touch lib/doctrine/Inflector_Cyrilic.php
touch lib/doctrine/Sluggable.php
touch test/unit/TransliterationTest.php
lib/doctrine/Inflector_Cyrilic.php:


你也可以在你的项目中修正这种行为。 多亏了symfony autoloader,它在插件启动之前预先设置了您的全局目录,您可以这样做:

mkdir lib/doctrine
touch lib/doctrine/Inflector_Cyrilic.php
touch lib/doctrine/Sluggable.php
touch test/unit/TransliterationTest.php
lib/doctrine/Inflector_Cyrilic.php:


好的,我试过了,但结果是一样的。函数仅适用于my Db中的拉丁名称:您能在问题中发布错误和带有西里尔字母问题的名称吗?是的!这个功能是什么。但令人失望的是,因为该学说不支持cirillic。在本例中,我修改了url whit+比拉丁语更好。好的,我试过了,但结果是一样的。函数仅适用于my Db中的拉丁名称:您能在问题中发布错误和带有西里尔字母问题的名称吗?是的!这个功能是什么。但令人失望的是,因为该学说不支持cirillic。在本例中,我修改了url whit+比拉丁语更好。
<?php

// some bootstrapping of your tests

$record = Doctrine_Core::getTable('YourTable')->create(array(
        'record params....'
    ));
$record->Translation['ru']->name = 'холодильник';
$record->save();
$t->ok(preg_match('/^holodilnik/', $record->Translation['ru']->slug), '        RU slug transliterated cyrilic to latin');
//i have this in my abstract class which is parent of each my cli tasks
require_once(implode(DIRECTORY_SEPARATOR, array(
        __DIR__, '..',
        'Doctrine',
        'Sluggable.php'
    )));