Search code examples
phpsymfony1doctrineslug

Expected path to Sluggable builder in Symfony/Doctrine


The default string normalization (provided by the Doctrine_Inflector::urlize() "sluggifier") isn't suitable for my project, so I need to utilize my own algorithm.

I set my schema up as follows:

MyObject:
  actAs:
    Sluggable:
      fields: [name]
      builder: array('TextUtility', 'normalize')
  columns:
    name: string(255)

And I added my utility class to the lib folder of my project (although I also tried the lib folder of an app) according to some instructions I found in another forum:

<?php
//lib/TextUtility.class.php

class TextUtility {
    public static function normalize($str) {
        /* ... */

        return $str;
    }
}
?>

When I run symfony doctrine:build --all I'm greeted by the following error:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'array('TextUtility', 'normalize')' not found or invalid function name in /symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Template/Listener/Sluggable.php on line 171

I assume I'm just putting my utility in the wrong place and it's not being loaded when needed. Am I putting it in the wrong place? Doctrine's documentation doesn't seem to mention the subject, unless I'm just looking at the wrong page.


Solution

  • arrays in YAML are defined other way:

    MyObject:
      actAs:
        Sluggable:
          builder: [TextUtility, normalize]