Hello. I have created a new Zend project, created a new model class to get some data from the database. If the environment is set to 'development', the data from the database are displayed properly in the browser, but after setting the environment to 'production', the following error appears:

An error occurred

Application error

Can anybody please help to find out the problem?

Recommended Answers

All 3 Replies

Can you confirm are you using ZF or ZF2?

Also there must be more to the error.

How have you set the error handling?

PHP Version 5.4.6

I have just created a new project, added Zend library, added the code

resources.db.adapter = PDO_MYSQL
resources.db.params.host = localhost
resources.db.params.username = myusername
resources.db.params.password = mypassword
resources.db.params.dbname = mydatabase
resources.db.params.charset  = UTF8
resources.db.isDefaultTableAdapter = true

into 'application.ini', created a subfolder 'DbTable' in 'models' and there created a file 'Mysqltablename.php' with the code

<?php

class Application_Model_DbTable_Mysqltablename extends Zend_Db_Table_Abstract
{
    protected $_name = 'mysqltablename';
}   

and the file 'IndexController.php' has the code

<?php

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
        $myModel = new Application_Model_DbTable_Mysqltablename();
    }

The file 'ErrorController.php' was automatically created and has the following code

<?php

class ErrorController extends Zend_Controller_Action
{

    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');

        if (!$errors || !$errors instanceof ArrayObject) {
            $this->view->message = 'You have reached the error page';
            return;
        }

        switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                // 404 error -- controller or action not found
                $this->getResponse()->setHttpResponseCode(404);
                $priority = Zend_Log::NOTICE;
                $this->view->message = 'Page not found';
                break;
            default:
                // application error
                $this->getResponse()->setHttpResponseCode(500);
                $priority = Zend_Log::CRIT;
                $this->view->message = 'Application error';
                break;
        }

        // Log exception, if logger available
        if ($log = $this->getLog()) {
            $log->log($this->view->message, $priority, $errors->exception);
            $log->log('Request Parameters', $priority, $errors->request->getParams());
        }

        // conditionally display exceptions
        if ($this->getInvokeArg('displayExceptions') == true) {
            $this->view->exception = $errors->exception;
        }

        $this->view->request   = $errors->request;
    }

    public function getLog()
    {
        $bootstrap = $this->getInvokeArg('bootstrap');
        if (!$bootstrap->hasResource('Log')) {
            return false;
        }
        $log = $bootstrap->getResource('Log');
        return $log;
    }


}

I have found out the problem.

The mistake was that I added the code for database configuration in 'application.ini' file in the wrong place, it needs to be under [production].

BEFORE:

    [production]
    phpSettings.display_startup_errors = 0
    phpSettings.display_errors = 0
    includePaths.library = APPLICATION_PATH "/../library"
    bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
    bootstrap.class = "Bootstrap"
    appnamespace = "Application"
    resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
    resources.frontController.params.displayExceptions = 0

    [staging : production]

    [testing : production]
    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1

    [development : production]
    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1
    resources.frontController.params.displayExceptions = 1

    resources.db.adapter = PDO_MYSQL
    resources.db.params.host = localhost
    resources.db.params.username = mydbusername
    resources.db.params.password = mydbpassword
    resources.db.params.dbname = mydbname
    resources.db.params.charset  = UTF8
    resources.db.isDefaultTableAdapter = true

AFTER:

[production]
    phpSettings.display_startup_errors = 0
    phpSettings.display_errors = 0
    includePaths.library = APPLICATION_PATH "/../library"
    bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
    bootstrap.class = "Bootstrap"
    appnamespace = "Application"
    resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
    resources.frontController.params.displayExceptions = 0

    resources.db.adapter = PDO_MYSQL
    resources.db.params.host = localhost
    resources.db.params.username = mydbusername
    resources.db.params.password = mydbpassword
    resources.db.params.dbname = mydbname
    resources.db.params.charset  = UTF8
    resources.db.isDefaultTableAdapter = true

    [staging : production]

    [testing : production]
    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1

    [development : production]
    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1
    resources.frontController.params.displayExceptions = 1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.