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

How can I debug the rendering of a view?

I have a multiple module application that is working absolutely fine. I have come across an issue that I am having trouble resolving. There is one url that wont render the relevant view.

I have the router configured like so:

$router->add("/user", array(
    'module'     => 'backend',
    'controller' => 'user',
    'action'     => 'index'
));

Inside the "UserController" I have an "indexAction" which is being called perfectly. I have the view file inside "apps/backend/views/user/index.phtml"

This file is not being rendered. I cannot understand why as the following route has exactly the same file structure to the view, and renders perfectly.

$router->add(
    '/admin/:controller', array(
    'module'     => 'backend',
    'controller' => 1,
    'action'     => 'index',        
));     

I understand that this could be very difficult for someone to help with without seeing the full code. If that is the case I would be very grateful if someone could tell me how I can debug this. I have Phalcon debuging enabled but it returns nothing as if everything is ok. For example is there a way to find out where Phalcon is looking for the view file?

Thanks in advance.



4.5k
Accepted
answer
edited Nov '14

You can attach a listener to your view service

$eventsManager = new Phalcon\Events\Manager();
$eventsManager->attach("view", function($event, $view) {
      if ($event->getType() == 'notFoundView') {      
        throw new Exception('View not found' . $view->getActiveRenderPath());
      }  
  });
  $view->setEventsManager($eventsManager);

This should show you what view file it tries to render, hopefully this will be helpfull for you



4.6k

Thanks mirago, works perfect!