Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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?



27.4k
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: http://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


1.2k

great, it's work!

Thank you very much.



7.0k

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);
    }
}