$column = 'this is a test';
$column = Inflector::slug($column, '_'); //result: this_is_a_test
$column = Inflector::slug($column, '_'); //result: thisisatest
this_is_a_test
It should not replace the replacements
thisisatest
| Q | A
| ---------------- | ---
| Yii version | 2.0.13.1
| PHP version | 7.1.4
| Operating system | Windows 10
I'd say this is expected behaviour as per the docs, http://www.yiiframework.com/doc-2.0/yii-helpers-baseinflector.html#slug()-detail
Returns a string with all spaces converted to given replacement, non word characters removed and the rest of characters transliterated.
It only replaces spaces so any subsequent calls would remove the replacements.
I didn't read the docs, i just assumed slug() would do the trick and make me a slug() ;-). Maybe it should be this way? Or renaming the function to replaceSpaces()?
I agree this to be strange behavior.
It makes no sense to replace and remove the same character at the same time.
The default works for a -, you'd need to include the replacement string in the regex.
Could use http://php.net/manual/en/function.preg-quote.php to add it.
Most helpful comment
I agree this to be strange behavior.
It makes no sense to replace and remove the same character at the same time.