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

Phlacon 3 view Pick different behavior than Phalcon 2 $this->view->pick

Hi guys,

my problem is when I change my mamp server to work based php 7 and phalcon 3 I ve got different result and behavior of using $this->view->pick than php 5.6 and phalcon 2 !!!

what should I do?

isn't it supposed to only render picked view file?

What is the different behavior? Perhaps your "layouts" are not loaded?


What is the different behavior? Perhaps your "layouts" are not loaded?

thats exactly my aim.. not rendering any view layouts except picked view !

I have used view pick for ajax call and returning only desired view file and not loading any other hierarchy views. which is worked perefecltly in Phalcon 2 though in Phalcon 3 it seems it renders action view, controller layout and main layout..

any suggestion? is it a bug?

I remember having the same problem when I switched to version 3. I think this is caused because absolute path suppot was added to the views.

Here is my volt service since 3.0:

$di->setShared('view', function() use ($di) {
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir(__DIR__ . '/views/');
    $view->setLayoutsDir(__DIR__ . '/views/_layouts/');

I would suggest playing with setLayoutsDir() and getLayoutsDir() methods to fix paths in your application.

edited Jan '17

I had no such issues after migration as I was using absolute paths in every application context. That is always recommended.

//Define APP_PATH on FPC (index.php)
define('APP_PATH', realpath('..'));

//Build shared config service
$config = new Configuration(APP_PATH . '/app/config/config.ini', INI_SCANNER_TYPED);

//View service config sample:

$view = new View();
$view->setViewsDir(APP_PATH . $config->application->viewsDir);