We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Controller Name using camelcase

Hi,, i was developing web a app with Phalcon on windows OS,

I created a controller MsCompanyController.php on windows and this controller works fine.

but when I run in linux I get error

MscompanyController handler class cannot be loaded

when I rename MsCompanyController.php to MscompanyController.php in linux it worked fine.

Anyone can help me, without renaming the controller filename, because I have wrote a lot of code?



40.8k
Accepted
answer
edited Mar '14

I wrote dedicated converter for your needs, it should work for you any controller parameter which goes to router, for example MsCompany, MyProfile.TryThis etc without adding dedicated routes, but take care about this converter and secure it

url: https://localhost/MsCompany/index
$router->add("/:controller/:action/:params",
    array(
        "controller" => 1,
        "action" => 2,
        "params" => 3
    )
)->convert('controller', function($controller) {
        $new_controller = array();
        for($i=0;$i<strlen($controller);$i++)
        {
            $lowercase = strtolower($controller[$i]);
            if(ord($controller[$i])<=90 && $i>0)
            {
                    $new_controller[]='_';
            }
            $new_controller[]=$lowercase;
        }
        return implode('',$new_controller);
    });
class MsCompanyController extends \Phalcon\Mvc\Controller
{
    public function indexAction()
    {
        $this->view->disable();
        echo "Controller: ", $this->dispatcher->getControllerName();
        echo "<br>";
        echo "Action: ",$this->dispatcher->getActionName();
    }
} 

output

Controller: ms_company
Action: index


2.4k

great, it's work!

Thank you very much.



8.1k

Strangely it all All works in default....

<?php 

namespace FM\Apps\Frontend\Controllers;

/**
 * Description of IndexController
 *
 * @author 
 * @RoutePrefix("/camel")
 */
class MyCamelController extends \FM\Apps\Frontend\Controllers\ControllerBase
{
    /**
     * [indexAction description]
     * @return [type] [description]
     * @Get("/")
     */
    public function indexAction()
    {
        $this->view->disable();
        var_dump($_SERVER);
    }
}


108

MsCompanyController.php on windows and this controller works fine??

My environment is windows also, it doesn't work. I must change it to MscompanyController.php