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.

Production environment

Where can I find some information about configuring production environment? The difference between production and development environment should be the following:

  • When controller is not found, it should just show 404 page. Is there a way to specify 404 page to be used by default?

  • In case of an exception, instead of showing the actual error message, it should just show internal error page

  • I would like to use two different baseUris in production and development version. Is there a better way to do this than the one suggested by supernovagurl here.



10.5k
Accepted
answer

1 - set a variable in the config to specify production / deveploment

'application' => [
        'siteUrl'        => 'http://something.net',
        'controllersDir' => APP_PATH . '/app/controllers/',
        'modelsDir'      => APP_PATH . '/app/models/',
        'viewsDir'       => APP_PATH . '/app/views/',
        'baseUri'        => '/',
        'production'   => false,

2 - When now use this variable in the service.php to configure the controller . If its in production 404 if not, phalcon debug mode will be on on the index.php

$di->set('dispatcher', function() use ($di, $config) {

        $dispatcher = new PhDispatcher();
        $dispatcher->setDefaultNamespace('Naruhodo\Controllers');

        //in production
        if($config->application->production)
        {
             //set event for 404
            $evManager = $di->getShared('eventsManager');

            $evManager->attach(
                'dispatch:beforeException',
                function($event, $dispatcher, $exception)
                {
                    switch ($exception->getCode()) {
                        case PhDispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                        case PhDispatcher::EXCEPTION_ACTION_NOT_FOUND:
                        default:
                            $dispatcher->forward(
                                array(
                                    'controller' => 'error',
                                    'action'     => 'show404'
                                )
                            );

                        return false;
                    }
                }
            );

            $dispatcher->setEventsManager($evManager);
        }

        return $dispatcher;
    },
    true
);

3- Base url I would use something similar to supernovagurl .

Let me know if you need any more help ;)

Thank you for your answer, Max Castro. This seems to solve the problem with not found controllers. How do I also specify "Internal Error" page in case of any exception in my app?



10.5k

In the controller, specify the view you would like to use ^^

In the controller, specify the view you would like to use ^^

I just added forwarding to catch block in index.php . Thanks for help :)

Found a simplier solution for 404 page Routing -> Not Found Paths, but I guess yours works just as well.



10.5k

Yeah that should also work :)

Found a simplier solution for 404 page Routing -> Not Found Paths, but I guess yours works just as well.