0

I want to have url example.com/invoice/id/5

Create action

function indexAction(){
  echo "test";
}

Now i try access this action from url

example.com/invoice/ or example.com/invoice/index

And also pass parameters

example.com/invoice/id/5

Here I'm get error because Zend try to render

id.phtml

My question is how to have url example.com/invoice/id/5 and not use example.com/invoice/index/id/5

Wizard
  • 10,985
  • 38
  • 91
  • 165

1 Answers1

1

By Default Zend Route as Follows: http://www.example.com/controller/action/param_name/param_value/param_name_1/param_name_1_value

For the custom URL, you have to define the routes in the Bootstrap.php as of Zf1.

$frontController = Zend_Controller_Front::getInstance(); $router = $frontController->getRouter();

    $router->addRoute(
                'someidentifier',
                new Zend_Controller_Router_Route(
                    '/invoice/:id',
                    array(
                        'controller'=>'invoice',
                        'action'=>'index'
                    )
                )
        );

If it is ZF2 I think you have to define the custom route in Module.php, onBootstrap function and attach to eventManager.

Gopi
  • 36
  • 1
  • Add this to controller action method ? – Wizard Oct 15 '14 at 12:14
  • Nope. If it is ZF1 you are using, you need to add the code to Bootstrap.php -> Method _initRoutes(). What you do in controller is you just need to add index action, and $this->getParam('id') will get the ID. – Gopi Oct 15 '14 at 17:48