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

"Partial not found in any of the views directory" exception

I have recently upgraded phalcon from 2.0.10 to 3.1.2 and PHP to version 7. Everything worked well before but seems its now broken after the upgrade

In index.php, i have set the partial directory like this-

$di->set('partials', function() {
                $partials = new View();
                $partials->setPartialsDir('../apps/common/views/');
                return $partials;
            });

And in index.phtml, the partial is called like this

$this->partials->partial("header");

header.phtml exist in ../apps/common/views directory.

When I run the site, it gives following error.

Fatal error: Uncaught Phalcon\Mvc\View\Exception: View '../apps/common/views/header' was not found in any of the views directory in D:\server\www\booktickets.com\frontend\apps\modules\books\views\index.phtml

The partial header.phtml is in partial directory. Can anybody shed light on this??



77.7k
Accepted
answer

afaik, setPartialsDir must be a relative path, and a View instance must also have it's viewsDir set (the absolute part).

$partials = new View();
$partials->setViewsDir('../apps/common/views'); // absolute path to views dir
$partials->setPartialsDir('./'); // relative path to partials dir within
return $partials;