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

Problem with my common view service for my application

Hi All,

I have a problem rendering a partial from a common view service in my application. Basically I have a multi module application ( 2 Modules ). Modules :

  1. Frontend
  2. Admin I have successfully registered a common view service like this in my service.php file :
    /**
    * Registering a shared view component
    */
    $di->set('commonv', function() {
        $view = new \Phalcon\Mvc\View();       
        $view->setViewsDir(APP_DIR.'/common/views/');        
         $view->setPartialsDir(APP_DIR.'/common/views/partials/');
        return $view;
    }, true);

The problem I have is when I actually try to display the common view like this :

    // show the common footer
    $di = $this->di->getDefault();
    $commonv = $di->get("commonv");
    // then in my view I do the following
    $commonv->partial('footer'));

Then I get an error message like this, :

    View 'C:\localhost\my-app/app/common/views/C:\localhost\my-app/app/common/views/partials/footer' was not found in the views directory
    #0 [internal function]: Phalcon\Mvc\View->_engineRender(Array, 'C:\\localhost\\my...', false, false, false)
    #1 C:\localhost\my-app\app\frontend\controllers\LoginController.php(31): Phalcon\Mvc\View->partial('footer')
    #2 [internal function]: Psg\my-app\Frontend\Controllers\LoginController->indexAction()
    #3 [internal function]: Phalcon\Dispatcher->dispatch()
    #4 C:\localhost\my-app\public\index.php(55): Phalcon\Mvc\Application->handle()

I can tell the paths do not look right, any advice on how I can fix it?

Thanks



98.9k
Accepted
answer

Path to the partials directory must be relative to the Views directory:

$view->setPartialsDir('partials/');


22.8k

Thanks @Phalcon! Will give it a try now



22.8k

Awesome it works! thanks!