2

I am a new Developer in Zend and I am working on a very simple application in Zend wich will allow me to publish the pages.

to do so, I need to create a way to get the controller name and action name if it does not exist.

e.g I have a controller named page and in the view action of that controller I display the page content based on the id I Pass. So he url will be:

http://localhost/page/view/slug/some-slug-value

I want that if I write the following link,

http://localhost/some-slug-value

instead of displaying Invalid controller error, it should also serch the db for that slug and open the view action in the page controller.

I don't want to change the URL http://localhost/some-slug-value even if i have to show some error.

If i had to process the invalid action, I can do it via the __call() function in that controller. so I need a __call function for handling invalid controllers.

As I am a new in Zend, please also mention where I have to write that code which you are going to suggest.

Thanks in advance

Balwant Singh
  • 287
  • 5
  • 14

2 Answers2

1

Zend_Controller_Plugin_ErrorHandler can handle the exception due to missing controller/action and is enabled by default. You can put your logic inside.

ngsiolei
  • 614
  • 3
  • 5
1

I have answered a similar question before using a custom plugin here.

Basically, it checks if a request can be dispatched and in the event it cannot, it redirects to another controller/action. This happens before the ErrorHandler plugin allowing for the ErrorHandler to handle errors only as intended.

EDIT

I should note that inn the plugin on the linked question, I referenced the username. In your case, you will have to substitute slug for username.

Community
  • 1
  • 1
brady.vitrano
  • 2,256
  • 2
  • 16
  • 26