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.

Issue with picking a view

Hi guys,

I've been on phalcon 1.x for a while now, and i just have a new project and wanted to try phalcon 2.x but i've issues when picking my view from the controller.

It seems the view is not find, but i've checked several times my paths it's okay

class CountryController extends ControllerBase
{
    public function addAction()
    {
        $this->view->pick("admin/country/add"); // Must find /app/views/admin/country/add.volt
    }
}

The view at the moment must print a Hello World ! but there is nothing on my screen. that's pretty weird it seems to work fine in phalcon 1.4.

Thanks for your time,

Greetings,

Brieuc

The problem seems not to be there, i currently use phalcon 2.0.10, and it works fine.

Check your services.php, maybe $view->setViewsDir(...) has a wrong path.

edited Apr '16

Hi thanks for your answer, i think it's set correctly:

viewsDir        = /app/views/
// app/config/loader.php
$loader->registerDirs(
    array(
        APP_PATH . $config->application->viewsDir,
    )
)->register();

// app/config/services.php
$di->setShared('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,
                'compiledSeparator' => '_'
            ));

            return $volt;
        }
    ));

    return $view;
});

I think it's very odd because i've no issues with my controllers using the same configuration, and it's not working. So if someone find what's wrong in this code, i'll appreciate it !

Thanks a lot really for your time !

Brieuc

What is APP_PATH and $config->application->viewsDir ?

edited Apr '16

This is the output of what you asked, that's why i don't understand what's going on here :/

APP_PATH = C:/wamp64/www/myProject
$config->application->viewsDir = /app/views

Try with:

$this->view->pick(["admin/country/add"]);

Notice the array as the parameter. In the beginning it was very confusing to me also :)

edited Apr '16

On windows it changes nothing, but i'll try it on linux.

I've find that i've some issues with backslash and trailslash

in fact i have :

APP_PATH = C:\wamp64\www\myProject\
$config->application->viewsDir = app/views/

Maybe it's a part of the problem, but i'm not able to convert slashes i don't know how to do it.

edited Apr '16

I have windows and that is not a problem, for example i have

C:\xampp\htdocs\test\app/views/

And it works fine :)

And according to the Phalcon Documentation, if you do the thing of the array, for example:

$this->view->pick(["admin/country/add"]);

It will pick: /app/views/admin/country/add/{ACTION}.volt in this case "add"

Once again thanks for your time, both of you !

It's still not working, i've made a branch on my git in order to show you exactly how it's configured.

Branch with the issue

That's very odd i had no issues with phalcon 1.4 :'(

edited Apr '16

The problem are not the views, there is other problems, i recommend you to use a new Skeleton, and insert your old controllers, models, libraries, etc, there.

https://github.com/phalcon/skeleton-single

Thanks again, It was my last idea recreate everything from scratch, This time, i won't use the project generator ;)

edited Apr '16

Your path are worng:

[application]
controllersDir  = /app/controllers/
modelsDir       = /app/models/
viewsDir        = /app/views/
formsDir        = /app/forms/
pluginsDir      = /app/plugins/
libraryDir      = /app/library/
cacheDir        = /app/cache/
router          = /app/config/router.php

config file is loaded in services. __DIR__ of services.php is /app/config. You need to change:

define('APP_PATH', realpath('..').'/');

to:

define('APP_PATH', realpath('..'));

And either put .. before /app in config.ini or :

$view->setViewsDir(APP_PATH.$config->application->viewsDir);
'compiledPath' => APP_PATH.$config->application->cacheDir,

Also compileAlways must be boolean.

Also for example router you are loading in proper way. Why then views in wrong ? Don't get it.

That was my configuration at the very beginning i've tried so many things that i've mixed up my minds. But even with your configuration it's not working, I'll follow angelvega93, I'll restart from scratch and i will strictly follow the documentation step by step.

Maybe by showing diffs between the two projects, i'll find my mistake !

Thanks a lot guys !!!

I will edit it tomorrow and set it to you working on my windows machine. You have wrong paths - that's all. Just fix them and you ready to go with. I already wrote were are your mistakes. In view definition you are just accessing $config->application->viewsDir but there is no views dir in /app/config dir.

edited Apr '16

Really thanks for helping me, but i did the updates and as result in my controllers of :

echo $this->view->getViewsDir();

I get :

'c:\wamp64\www\my-project/app/views/'

So it seems to be set correctly, but still nothing showing up !

And you changed cache dir too ? You have this view even created ? Beacause in files you posted you don't.



730
Accepted
answer

Find where was the problem, but don't understand why !

$application->useImplicitView(false);

I really don't know why but it makes crash the volt engine ...

Thanks a lot guys ! Really you did a great job helping me !

I'll let the topic unanswered just if someone knows why useImplicitView is making volt crash, in 24h without answers i'll accept the answer !