0
votes

I recently started a new zend framework project. I created all the db-table models, models, controllers, actions, forms and enabled layouts via the ZF Tool. All of the items I created show up in .zf-project.xml.

I then set about setting up the first header and footer for the default layout. At the bottom of this layout is a footer nav section with several links for example:

    <a href="/howitworks">How it Works</a>

When this is clicked it should navigate to the index controller / howitworksAction however it doesn't. Instead I get an error stating:

    Message: Invalid controller specified (howitworks)

    **Stack trace:**

    #0 /usr/share/php/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
    #1 /usr/share/php/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
    #2 /usr/share/php/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
    #3 /var/www/vhosts/lokals.mediagiantdesign.com/httpdocs/public/index.php(26): Zend_Application->run()
    #4 {main}  
    Request Parameters:

    array (
      'controller' => 'howitworks',
      'action' => 'index',
      'module' => 'default',
    )  

If I force the URL to /index/howitworks it works fine. I am totally thrown off by this as this is the first Zend application that I have built where this has ever happened. In previous applications this linking worked right out of the box. I haven't setup a custom router, the bootstrap is barebones. So I have no idea why this isn't working.

I thought zend first looked for a controller matching the controller, if not found it looked in index looking for an action that matched, and if that wasn't found, it would assume it was a file in /public. If that's the case, then what am I missing here?

Thanks in advance. Rick

2

2 Answers

2
votes

The default Zend Framework url structure is : http://yourdomain.com/controller/action/params. Whenever Zend Framework routes a URL by default, of the form "http://yourdomain/howitworks", it considers the howitworks as the controller and since no action specified, indexAction will be assumed. It is always helpful to use the Zend url view helper to avoid confusion.

    <a href="<?php  echo $this->url(array('controller' => 'index', 'action' => 'howitworks'), null, true); ?>"

If you want to use "/howitworks" point to howitworksAction in the IndexController, you will need to set up a custom route in the bootstrap.php.

1
votes

By default the URL domain.com/howitworks will refrence indexAction in howitworksController. If that isn't found Zend will continue to the error controller to findout how to hande the error. It does not go to the indexcontroller by default unless you have a route or some errorhandling in the errorController that tells Zend to use this fallback