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 to disable the views in any application?

I am creating an application with various modules and currently it uses the following code to disable all the view in each module:

namespace Multiple\Frontend;

 class Module {

     public function registerAutoloaders() {
         $loader = new \Phalcon\Loader();
         $loader->registerNamespaces(array(
             'Multiple\Frontend\Controllers' => __DIR__ . '/controllers/',
             'Multiple\Frontend\Models'      => __DIR__ . '/models/',
         ));
         $loader->register();
     }

     public function registerServices($di) {
         $di->set('dispatcher', function() {
             $dispatcher = new \Phalcon\Mvc\Dispatcher();
             $dispatcher->setDefaultNamespace('Multiple\Frontend\Controllers\\');
             return $dispatcher;
         });
         $di->set('view', function() {
             $view = new \Phalcon\Mvc\View();
             $view->disable(); // <---------------------------------------------------
             return $view;
         });
     }

 }

I would like to know there is a smarter way to do this only once for the entire system.



98.9k
Accepted
answer

You can use Phalcon\Mvc\Application::useImplicitView(false) to globally disable the view

https://api.phalcon.io/en/1.3.3/Phalcon/Mvc/Application#useImplicitView-details