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

Volt fails to find Controller/Action files.

Hello!

I've been using Phalcon for a while and I love it! Just recently, I wanted to put stuff on our completely clean staging environment (this is a new project), and everthing worked well, except for one thing: Phalcon appears to be unable to find the Volt-files for the Controller/Action. I store the view files in folders with the controller name and then with the actionname.volt as the file name. Therethrough, I use the implicit method of finding and rendering specific pages.

Everything works perfect locally, but on the staging / production servers, no content is returned from those files.

  • Phalcon successfully renders index.volt (and partials inside) from the Views-directory
  • There are no errors (full error reporting and Apache-access available)
  • $this->getContent() in the compiled file returns only an empty string.

  • Server runs Ubuntu, locally, I run Mac OSX.

I don't even know where to look for errors. Why doesn't Phalcon find the action view files?

Thanks for your time, hope I made sense.

Best regards, dimhoLt



98.9k

Hi, Mac OS X have a case-insensitive filesystem, and Ubuntu a case-sensitive file system, maybe while the paths are ok, the case sensitiveness prevent PHP find the paths.



22.6k

Hi! Yeah, I though of that possibility, but it seems correct (unless Phalcon assumes lower-case folder names). My tree looks like this:

  • app
    • app/Controllers/IndexController:indexAction()
    • app/Views/Index/index.volt

Edit: No, you were right. If I only changed the directory names of the controller-representing directories, I got it working. Is there a way to tell Phalcon that the directories should have the exact same name, except that the word "Controller" has been cut from it?



98.9k

Actually no, Phalcon "normalize" the controller names to lowercase in the views. Maybe a plugin can be created for that:

$di['dispatcher'] = function(){

    $eventsManager = new Phalcon\Events\Manager();

    $eventsManager->attach('dispatch:afterDispatchLoop', function($event, $dispatcher) {        
        $dispatcher->setControllerName(Phalcon\Text::camelize($dispatcher->getControllerName()));        
    });

    $dispatcher = new Phalcon\MVc\Dispatcher();
    $dispatcher->setEventsManager($eventsManager);

    return $dispatcher;
};