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 Engine cannot read views templates under Kubuntu 14.04

Hi, I have a problem with Phalcon on this distribution. I was developing a game under Windows, but now I decide to try Linux. Everything have worked on Windows, but now when I open localhost on Linux, I see only blank page. When I see the source code, it shows me that the layout template is loaded(all js libraries are shown, that's how I know the volt works). My main route ( / ) goes to IndexController which should load index/index.volt template, but it doesn't work. I've tried to open other links (which must open other templates) but the same sh*t. When I use

$this->view->pick('index/index');

display me the template, but is this the only way to work for me ? On windows everything have worked good without "pick" method.

I am using latest phalcon version for 64-bit OS which I have build by myself.

Thanks in advance! Hope someone can help me!

edited Aug '14

Paste here your error log from (/var/log/apache2/error.log) or from you custom path log. Or try to set permissions to cache folder.



1.2k

Hi, thanks for your reply. I have no errors in error log.

Folder has 0777 permissions ( as the whole site folder ), and also I force the apache to use my user and group for writing in that folder, but nothing works. Only main layout /app/views/index.volt has been cached. When I open the site, should open /app/views/index/index.volt template and must cache it, because my route goes to IndexController::indexAction, but guess - not working. I think the path to views is right, because if I change the views path phalcon cannot find index.volt .



1.2k

That's what I said, on Windows everything works fine, controllers access to templates, but on Linux - it doesn't work. I don't want to use pick method.

$di->set('view', function() {

        $view = new \Phalcon\Mvc\View();

        $view->setViewsDir('../app/views/');

        $view->registerEngines(array(
            ".volt" => function($view, $di) {
                $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);

                $volt->setOptions(array(
                    'compiledPath' =>  '../cache/volt/',
                    'compiledSeparator' => '_'
               ));

                return $volt;
            }
        ));

        return $view;
    });

I have {{ content() }} everywhere where i am not using blocks.

<!-- /app/views/index.volt -->
<!DOCTYPE html>
<html>
    <head>
        {{ get_title() }}
        <meta charset="utf-8" />
        {{ stylesheet_link('css/bootstrap.min.css') }}
        {{ stylesheet_link('css/bootstrap-theme.min.css') }}
        {{ stylesheet_link('css/layout.css') }}
        {{ javascript_include('js/jquery.js') }}
        {{ javascript_include('js/bootstrap.min.js') }}
        {{ javascript_include('js/jquery.validate.min.js') }}
        <script src="https://cdn.socket.io/socket.io-1.0.6.js"></script>
        {% block additional_styles %}{% endblock %}
    </head>

    <body>
        {{ content() }}
        {% block content %}{% endblock %}

        {% block additional_js %}{% endblock %}
    </body>
</html>
{# /app/views/index/index.volt #}
{{ content() }}

<header id="main-information">
    {% if username is defined %}
        {{ partial('index/top.menu') }}
        {% if hasCharacter %}
            {{ link_to('logout', 'Logout') }} || {{ link_to("characters/create", "Create new character") }} 
        {% else %}
            {{ partial('character/ui.partial', ['data': charData, 'username': username]) }}
        {% endif %}
        {# ако има вече герой, то на мястото на линка се слага името на героя, което може да се избира. #}
    {% else %}
        {{ partial('account/login') }}
    {% endif %}
</header>

This works fine on Windows. I have not changed anything.

I am trying to drive it about a week ago already and i am blowing my mind, because I can't understand where is the problem.



1.2k

Now I've tried to get rendered controller and action with

$this->view->getControllerName(); // returns NULL
$this->view->getActionName(); // returns NULL

both methods returns me NULL. I am not sure, but I think should show me Index(Controller) and index(Action) if try to renders them from views folder.



98.9k
Accepted
answer

It seems to be a problem with a case sensitive filesystem, some of the paths who were previously accesible are not now due to the case sensitiveness of linux's filesystem. I would use Strace to see which files are being open by PHP.

cd /path/to/my-app/public
strace php index.php


1.2k

There is a lot of files which tries to open, but I can't understand anything.

https://pastebin.com/qCvta4zU - here is the result.

Thanks in advance!



98.9k

You have to load Phalcon in CLI too, you have to create a file called 50-phalcon.ini in /etc/php5/cli/conf.d/ and re-run strace

@phalcon

I have a similar issue. On my development envirnoment (os x) everything works, on production server doesn't (ubuntu server). Views not loading - I'm getting blank page. How to resolve this?



1.2k

I am really thanks to @phalcon for his help. The reason to not showing anything is that case-sensitive of the filesystem, as @phalcon said before(but I didn't understood what that means at all). So I run strace and I reach the line where the php tries to open /app/views/Index/index.volt which is not a real path for Ubuntu. To run the application you need to rename all your folders in views which meet controllers name.

So if you have IndexController your folder should be Index, not index (not with lower case of first letter).



1.2k

@phalcon , is there any option in future releases to make controllers looking for case-insensitive folders ? This would help a lot of people which change the OS.



98.9k

@relax4o I don't think so, support something like this would be really hard. The case sensitivity of Phalcon depends on the case sensitivity of the underlying file system. To support this in a framework level we have to make so many stats as every character in the requested path:

Path: /srv/www/htdocs/app/views/index.volt
Real Path: /Srv/WWW/htDocs/App/Views/Index.volt

So we have to try:

/Srv/www/htdocs/app/views/index.volt
/sRv/www/htdocs/app/views/index.volt
/srV/www/htdocs/app/views/index.volt
/SRv/www/htdocs/app/views/index.volt
...

Stat every possible path in every request will take more time, stat that number of files will take many seconds, this will make the application slower.

edited Aug '14

@phalcon

I think that making all views directories/files to lowercase (by framework) is sufficient. For example views directories/files should be:

/Srv/WWW/htDocs/App/Views/index/index.volt

/Srv/WWW/htDocs/App/Views/index.volt

/Srv/WWW/htDocs/App/Views/layouts/main.volt



98.9k

You just have to define controller and action in lowercase in the routes so they will stay in that form when views are look up.

I use annotation router and have this issue. For example i have CompaniesController.php:

<?php

namespace App\Controllers;

/**
 * Class CompaniesController
 * @package App\Controllers
 *
 * @RoutePrefix("/companies")
 */
class CompaniesController extends ControllerBase
{
    /**
     * @Route("/show/{id}")
     */
    public function showAction($id)
    {
        ...
    }
}

The controller and action in routing is lowecase and the problem occurs.



98.9k

They aren't in lowercase, what the annotations router does is extract controller name from class name by removing the "Controller" suffix:

CompaniesController -> Companies
showAction -> show


1.2k

Oh, yes, I've not complied that there is many variations of folders names. That's not a big problem, but may be you can reflect this in documentation, that some OS have no case-insensitive filesystems. It would direct people with same issue to the right way.

This is only advice, sorry if I am too insolent.