Invalid controller using custom routes

Posted by AlexW on Stack Overflow See other posts from Stack Overflow or by AlexW
Published on 2012-03-25T01:26:45Z Indexed on 2012/03/25 5:30 UTC
Read the original article Hit count: 241

Filed under:

I've been following the instruction on how to create custom routes from the book Zend Framework - A Beginners Guide

I've changed my application.ini file to include this routing information:

resources.router.routes.static-content.route = /content/:page
resources.router.routes.static-content.defaults.module = default
resources.router.routes.static-content.defaults.controller = static-content
resources.router.routes.static-content.defaults.view = static-content
resources.router.routes.static-content.defaults.action = display

Given the above configuration, I have this controller:

<?php

class Default_StaticContentController extends Zend_Controller_Action
{

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

    public function displayAction()
    {
        // action body
        $page = $this->getRequest()->getParam('page');
        if (file_exists($this->view->getScriptPath(null) . 
                '/' . $this->getRequest()->getControllerName() . '/' .
                $page . $this->viewSuffix
                )) {
            $this->render($page);
        }
        else {
            throw new Zend_Controller_Action_Exception('HLC - Page not found', 404);
        }
    }
}

I have a view named about.phtml in the APPLICATION_PATH/modules/default/views/static-content folder.

What ahppens is I get an error saying:

An error occurred

Page not found

Exception information:

Message: Invalid controller class ("StaticContentController")

Stack trace:

#0 /Applications/MAMP/htdocs/zend/library/Zend/Controller/Dispatcher/Standard.php(262): Zend_Controller_Dispatcher_Standard->loadClass('StaticContentCo...')
#1 /Applications/MAMP/htdocs/zend/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#2 /Applications/MAMP/htdocs/zend/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#3 /Applications/MAMP/htdocs/zend/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#4 /Applications/MAMP/htdocs/HLC/public/index.php(26): Zend_Application->run()
#5 {main}  
Request Parameters:

array (
  'page' => 'about',
  'module' => 'default',
  'controller' => 'static-content',
  'view' => 'static-content',
  'action' => 'display',
) 

Note that it is not rendering my customised Zend_Controller_Action_Exception but throwing the global error.

I'm using the URL: http://hlc.local:8888/content/about

The default index action works ok, just this routing that's not working.

© Stack Overflow or respective owner