Search code examples
phpmodel-view-controllerzend-frameworkzend-controller

Zend Controller all actions to one action


I have categorie Controller, with index action

I need that when I enter address .com/categorie/education it uses index action with parameter education .com/categorie/index/education

or redirect all actions to index ??


Solution

  • How are your routes setup? Given the lack of information provided I have to assume that you are using an .ini file, this is how it would work:

    ; CATEGORIE
    categorie.type = "Zend_Controller_Router_Route_Static"
    categorie.route = "categorie"
    categorie.defaults.controller = categorie
    categorie.defaults.action = index
    
    categorie_view.route = "categorie/:slug"
    categorie_view.defaults.controller = category
    categorie_view.defaults.action = view
    

    Note, I did change it up a bit, as the index action, imo, should list all categories. This way you have a viewAction to list the individual categorie.

    To have it as you requested I believe it would be something like:

    ; CATEGORIE
    categorie.route = "categorie/:slug"
    categorie.defaults.controller = categorie
    categorie.defaults.action = index