Question

I have a problem with Zend Framework 1.11.11. When I call a Action, the view is showing 3 times, like this:

Test and script/action name index

Test and script/action name index

Test and script/action name index

It occurs for all the ActionControllers. And in "views/scripts/test" there is de .phtml with only one sentence. I don't know why. Could you help me? Thank you!

this is my bootstrap.php

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    /**
     * Loading configuration from ini file
     */

  protected function _initView() {  

        $view = new Zend_View();  
        $view->setEncoding('UTF-8');  
        $view->doctype('XHTML1_STRICT'); 
        $view->headTitle('My first zenRaul Framework app'); 
        //$view->headMeta()->appendHttpEquiv('Content-Type','text/html;charset=utf-8');  

        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');  
        $viewRenderer->setView($view);  

       // return $view;  
    } 


}

UPDATE: application.ini

[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
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 = 1
phpSettings.date.timezone = "Europe/Madrid"

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
[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

UPDATE2: /var/www/ZendProject/public/index.php

<?php

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();

$rdir = realpath(dirname('SCRIPT_NAME'));

set_include_path($rdir . '/library' . PATH_SEPARATOR . get_include_path());


try {
    // use Autoloader to load the Zend classes
    // instead of Zend_Loader::loadClass('Zend_Controller_Front');
    // a smarter alternative for larger projects
    require_once('Zend/Loader/Autoloader.php');
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->setFallbackAutoloader(true);

    $fcontroller = Zend_Controller_Front::getInstance();

    $fcontroller->throwExceptions(TRUE);
    $fcontroller->setParam('noErrorHandler', TRUE);
    $fcontroller->setControllerDirectory("$rdir/application/controllers");

    $fcontroller->dispatch();

} catch (Exception $e) {
    $contentType = 'text/html';
    header("Content-Type: $contentType; charset=utf-8");
    print 'An unexpected error occurred:';
    print '<h2>Unexpected Exception: ' . $e->getMessage() . '</h2><br /><pre>';
    print $e->getTraceAsString();
}
Was it helpful?

Solution 2

SOLVED! this part in index.php was causing the problem! I remove it Thank you!

try {
    // use Autoloader to load the Zend classes
    // instead of Zend_Loader::loadClass('Zend_Controller_Front');
    // a smarter alternative for larger projects
    require_once('Zend/Loader/Autoloader.php');
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->setFallbackAutoloader(true);

    $fcontroller = Zend_Controller_Front::getInstance();

    $fcontroller->throwExceptions(TRUE);
    $fcontroller->setParam('noErrorHandler', TRUE);
    $fcontroller->setControllerDirectory("$rdir/application/controllers");

    $fcontroller->dispatch();

} catch (Exception $e) {
    $contentType = 'text/html';
    header("Content-Type: $contentType; charset=utf-8");
    print 'An unexpected error occurred:';
    print '<h2>Unexpected Exception: ' . $e->getMessage() . '</h2><br /><pre>';
    print $e->getTraceAsString();
}

OTHER TIPS

I don't know what else you must have done to the setup like the application.ini or if what i am about to suggest would solve your problem but to get the view in your bootstrap I use the snippet below.

protected $_view;

protected function _getView() {
    if ($this->_view == null) {
        $this->_view = Zend_Layout::startMvc()->getView();
    }

    return $this->_view;
}

This is situated in my Bootstrap.php file. so whenever I need to get the view, I just simply call $this->_getView(). Creating a new view object to me seems like complicating the matter. I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top