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

Simple View function render error

Hi, probably i found bug, but i wold like to be sure.

in my library i create function:

 public function getTemplate($templateName, $params) {
        $parameters = array_merge(array('baseUri' => $this->request->getHttpHost()), $params);
        $simpleView = new \Phalcon\Mvc\View\Simple();
        $simpleView->setViewsDir($this->view->getViewsDir());
        return = $simpleView->render('email/'.$templateName.'.volt', $parameters);
    }

and i got error: View /var/www/html/apibase.loc/app/modules/admin/views/email/resetPass.volt was not found in the views directory

under this path is file (opened via vim), so i don't know what can be wrong, can anybody check this?

Phalcon version 3.0.3

Hi, can you paste the code of using this function?



7.6k

call frunction from controller. Library isn't loaded via DI

$myLibrary = new MyLib();
$content = $myLibrary->getTemplate('resetPass', ['key' => 'value']); 


7.6k

ok, i had to resign from voltEngine and using .phtml files :( My solution is:


    public function getTemplate($templateName, $params = []) {
        $parameters = array_merge(array('baseUri' => $this->request->getHttpHost()), $params);

        $view = new \Phalcon\Mvc\View\Simple();
        $view->setViewsDir($this->view->getViewsDir());
        $view->render('email/' . $templateName, $parameters);
        return $view->getContent();
    }

if someone can enable correctly voltEngine in Library in HMVC please share :)

try simply to register engine

$simpleView = new \Phalcon\Mvc\View\Simple();
$simpleView->registerEngines([
    '.volt' => function ($simpleView, $di) {
        $volt = new VoltEngine($view, $di);
        $volt->setOptions(...); // set options
        return $volt;
    }
]);

You need to register volt engine.