I am working on a contact form in ZF 1.9. In one of my actions, I am
trying to access the bootstrap by
$this->getFrontController()->getParam('bootstrap')

I made some changes to the application.ini file that shouldn't affect
anything ... but now the code above is not returning the bootstrap. In
fact, $this->getFrontController() returns NULL -- I am not sure why?
It was working fine before ...

Here is my application.ini file
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
phpSettings.date.timezone = "America/Chicago"

includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.layout.layout = "layout"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"

contactMail.fromAddress = [email protected]
contactMail.fromName = Contact form
contactMail.toAddress = [email protected]
contactMail.toName = Some Name
contactMail.subject = "Contact Form Message on xyz.com"

[staging : production]

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

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

Here is the code in the action method:


    public function createAction()
    {
        if (!$this->_request->isPost()) {
            return $this->_forward('new');
        }

        $form = new Form_Contact();
        $formData = $this->_request->getPost();
        if (!$form->isValid($formData)) {
            return $this->_forward('new');
        }

        // Check for honeypot to avoid spam
        if ($form->getValue('altEmail')) {
            return $this->_forward('spam');
        }

        $view = new Zend_View();
        $path = APPLICATION_PATH . '/views/scripts';
        $view->setScriptPath($path);
        $view->name = $form->getValue('contactName');
        $view->phone = $form->getValue('phone');
        $view->email = $form->getValue('email');
        $view->comments = $form->getValue('comments');

        $bootstrap = $this->getFrontController()->getParam('bootstrap');
        if ($bootstrap->getEnvironment() == 'production') {
            $config = new Zend_Config($bootstrap->getOption('smtp'));
            $mail = new Zend_Mail('utf-8');
            $mail->setFrom($config->fromAddress, $config->fromName);
            $mail->addTo($config->toAddress, $config->toName);
            $mail->setSubject($config->subject);
            $mail->setBodyHtml($view->render('mail/contact.phtml'));
            $mail->send();
        }

        $this->_redirector->gotoSimple('show');
    }

Reply via email to