Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.



81.8k
Accepted
answer

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

http://api.phalconphp.com/en/1.3.3/Phalcon/Mvc/Application#useImplicitView-details