Text::camelize()

According to this post: http://stackoverflow.com/questions/12263294/phalcon-text-camelize-uncamelize-usage

The camelize function will strip whitespace which is what I'm expecting however this isn't happening?



20.3k

From the second message:

The camelize/uncamelize methods are intended to convert strings with underscores to camel case ones. Specifically, these methods are used by Phalcon\Model to convert table names to their respective classes and vice versa. Thus, we can get the name of a table from the class name.

So your expected behavior doesn't work.

edited Sep '14

Camelize should strip the whitespace, doing further testing the function isn't even converting the text to camelCase.

\Phalcon\Text::camelize("Property Details"); // returns "Property details" when it should be "propertyDetails"


20.3k

Show your code.

Have you even tested this in your instance? Code is as supplied just inside a function that returns the value.

public function getId()
{
    return \Phalcon\Text::camelize($this->getName());
}


20.3k
edited Sep '14

My action controller:

public function indexAction()
{
    echo '<pre>';
    echo \Phalcon\Text::camelize("property details");
    echo '<br>';
    echo \Phalcon\Text::camelize("property_details");
    echo '<br>';
    echo \Phalcon\Text::uncamelize("PropertyDetails");
    die();
}

The output:

Property details
PropertyDetails
property_details

So, it seems that camelize() is using ucfirst(), not ucwords(). But I the github repo it only appears that it calls itself, not one of the other two methods. @phalcon , we need you here.



85.3k

The camelize/uncamelize methods are intended to convert strings with underscores to camel case ones

It doesn't say it converts whitespaces.

But the results coming out aren't expected either, see previous posts... In every framework I've used their implementation of camelCase is like that.

The function isn't even doing camel case.

The camelize/uncamelize methods are intended to convert strings with underscores to camel case ones

It doesn't say it converts whitespaces.