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

actions view issue on live server

When i working on localhost, following codes working with lists/index.volt view file automaticly.

ListsController.php

public function indexAction()
{
    // someting
}

But on live server, content area is empty. Only working when i use pick function.

public function indexAction()
{
    $this->view->pick('lists/index'); // Why i should use this method on live server?
}

Which type of web server do you use on both envIronments? And how did you set BaseUrl in URL component?



58.1k

Config

return new Config([
    'application' => [
        'controllersDir' => APP_DIR . '/controllers/',
        'modelsDir' => APP_DIR . '/models/',
        'formsDir' => APP_DIR . '/forms/',
        'viewsDir' => APP_DIR . '/views/',
        'libraryDir' => APP_DIR . '/library/',
        'pluginsDir' => APP_DIR . '/plugins/',
        'cacheDir' => APP_DIR . '/cache/',
        'tasksDir' => APP_DIR . '/tasks/',
        'eventsDir' => APP_DIR . '/events/',
        'helpersDir' => APP_DIR . '/helpers/',
        'baseUri' => 'https://www.domain.com/',
        'publicUrl' => 'https://www.domain.com',
        'partialsDir' => 'partials/',
        'themesDir' => 'themes/',
    ]
);

Services

$di->set('config', $config);

$di->set('url', function () use ($config) {
    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);
    return $url;
}, true);

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

    $view = new View();
    $view->setViewsDir($config->application->viewsDir);
    $view->registerEngines(array(
        '.volt' => function ($view, $di) use ($config) {

            $volt = new VoltEngine($view, $di);

            $volt->setOptions(array(
                'compiledPath' => $config->application->cacheDir . 'volt/',
                'compiledSeparator' => '_',
                'compileAlways' => true
            ));

            return $volt;
        }
    ));

    return $view;
}, true);

Local Server:

PHP Version 5.6.15

Apache 2.0 Handler

Live Server:

PHP Version 5.6.19

CGI/FastCGI

What do you need server information about extensions or modules?



58.1k

I set baseUri as / but still doest working.

By the way, not only indexAction, this issue about all actions.

edited May '16

baseUri should be always relative to the server root, so you should never hardcode domain name (with http prefix) in it...

Try to handle your entire bootstrap (index.php) with try/catch block to see if there are any messages making it not work.

By the way, not only indexAction, this issue about all actions.

That is actually better, then to have only some actions working and vice versa for some.

edited May '16

Do you have any difference in URL while accessing your project on dev vs. prod environment, i.e. https://localhost/project/public or https://localhost/project ? Same stand for your PROD env. I think you misconfigured /public on prod and that's why it cannot find your volt files by default, but it does when you manually specify volt files.



58.1k

Already have try/catch block but no error, only empty content area.

On localhost, i'm using same domain name with vhost alias. So no config changed.

The project on root and when i write wrong baseUri like that /blablabla/, site files and looks are gone. So baseUri is correct.

So all of your assets load fine, like CSS styles and JS? You don't get any 404 errors while in 'F12' mode of your browser (network tab)?

Once again, do you access your project with /public visible in address bar or not (i.e. just www.domain.name)?



58.1k

Yes all assets load fine and no errors on chrome console. I'm already checking allways.

I dont use /public/ folder. Bootstrap index.php is on the root like that /home/user/public_html/index.php.

Well, usually public dir is only for public access, while your app resides up one directory away from public eyes. That might be your issue. Your bootstrap index.php is in a web server's root. I have to check your config.ini.



58.1k

Allways bootstrap index.php should be under the /public/ folder?

edited May '16

It's general rule, you don't need to follow that structure as-is, but I think that might be your issoue with autoloading.

What is this variable in your config, and where do you use it? "publicUrl" => "https://www.domain.com"

Also, where do you set APP_DIR constant: "viewsDir" => APP_DIR . "/views/"

From your structure, can you access yoursite.com/views/ in your browser?



58.1k
edited May '16

/public_html/app/config/config.php and variable is my domain name like that https://www.domain.com.

APP_DIR is /relativepath/public_html/app

Also i changed viewsDir to /relativepath/public_html/themes/default/views/ but nothing changed.

Application files on localhost and live server are same. Domain name, paths and everthing are same. Except server, localhost and live.

Which app or server configuration missed?

edited May '16

@afbora: Could you try to define APP_DIR with define("APP_DIR", realpath("..")); and to set your views dir in accordance with that path: viewsDir = /views/

And please provide full structure of your project, i.e.

/usr/share/nginx/project/ 
views
app
index.php (bootstrap)
edited May '16

@afbora Have you solved this issue yet?



58.1k

I defined APP_DIR like your said but nothing change. Still continue the issue :\



58.1k
edited May '16

@afbora Have you solvoed this issue yet?

I use router, this issue about the router? For ex:

$router->add('/arama', array(
    'controller'    => 'Search',
    'action'        => 'index'
));

and view file /views/search/index.volt path.

Is your dev environment GNU/Linux or Windows based?



58.1k

My local is Windows based, live server is linux.



11.6k
edited May '16

@afbora Have you solvoed this issue yet?

I use router, this issue about the router? For ex:

$router->add('/arama', array( 'controller' => 'Search',
'action' => 'index' ));

and view file /views/search/index.volt path.

windows is case insensitive, where linux is case sensitive... I see you use 'Search' with uppercase S, it won't work on linux...that's could be your problem..keep that in mind alo when you define your database tables names..



79.0k
Accepted
answer
edited May '16

My local is Windows based, live server is linux.

At last! You need to set your routes to lower case, i.e. the same way how you access them!

So all this trouble was due to using Windows which had lied to you. There are many reasons to avoid Windows if you are a web developer.

But then again, how did your Routes worked at all with camel case on GNU?! You only had issue with Volt files.



58.1k

I changed all controller names as lowercase in routes and fixed. Ohh, great!

@stamster really thanks to help so much.

@graphmatic thanks to catch good point.

@afbora I'm glad that you finally can run your app on production server! And beware next time you play on Windows :)



58.1k

Windows and IE allways problem :)))