Case insensitive path for views & layouts files

Hi,

First, I want to thank you for the outstanding work you have done with the Phalcon project.

I'm trying to switch from a custom Zend Framework webapp working only by namespaced conventions to your framework and I have the following problem:

All my files views are namespaced classes (as all my php files), for example the view file for the controller Index and the action Foo is in the directory MYAPPPATH/View/Index/Foo.php.

I wrote a Phalcon view engine to handle my view file as classes but the Phalcon/Mvc/View does not found the file MYAPPPATH/View/Index/Foo.php, it only finds MYAPPPATH/View/index/foo.php

I don't understand why you force the code $view->render('A', 'b') to render the file a/b.ext instead of A/B.ext…

How can I hack this feature, it seems to be the only problem switching my webapp to Phalcon.

Thank.



81.8k

Try modifying the way Phalcon pass parameters to the view component:

<?php

class CustomRenderer extends Phalcon\Mvc\User\Plugin
{
    public function viewRender($event, $application, $view)
    {
      $dispatcher = $this->dispatcher;

      $controllerName = str_replace('\\', DIRECTORY_SEPARATOR, $dispatcher->getNamespaceName()) . 
              DIRECTORY_SEPARATOR . 
          $dispatcher->getControllerName();

      $view->render($controllerName, $dispatcher->getActionName(), $dispatcher->getParams());
    }
}

The plugin must be attached to the application:

$evManager->attach('application:viewRender', new CustomRenderer());
$app = new Phalcon\Mvc\Application($di);
$app->setEventsManager($evManager);

Thank for your quick answer ; I now understand how I can bypass the default parameters to the view component.

However, I think it's a bad design to force the lower case of controller name and action name. Puting this code in my startup file app ```php $di = new \Phalcon\DI\FactoryDefault(); $di->set('dispatcher', function() use ($controllerNamespace, $controllerName, $action) { $dispatcher = new \Phalcon\Mvc\Dispatcher(); $dispatcher->setControllerName('INDEX'); $dispatcher->setActionName('INDEX');

    return $dispatcher;
});

```

and this code ```php die("<pre>\n" . $dispatcher->getControllerName() . '::' . $dispatcher->getActionName() . "</pre>\n"); ``` in the method viewRender of my custom mvc user plugin, I obtain index::index. I cant figure why the setter modify the value that I want to set. It's a bad design to call a controller class named Index when the controllerName of the dispacher is index. "Zend Framework", "Symfony Framework", the PHP "Framework Interop Group" <http://www.php-fig.org/> tend to standardes naming convention that help developper to have a reliable architecture as Java has. I suggest you to read this repository http://tinyurl.com/6f46w8q