Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3301220
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:43:51+00:00 2026-05-17T20:43:51+00:00

I am using a custom Router to enable pages like: mytutorialsite.com/category/:categoryname # added to

  • 0

I am using a custom Router to enable pages like:

mytutorialsite.com/category/:categoryname

# added to application.ini
resources.router.routes.categorynameOnCategory.route = /category/:categoryname
resources.router.routes.categorynameOnCategory.defaults.module = default
resources.router.routes.categorynameOnCategory.defaults.controller = category
resources.router.routes.categorynameOnCategory.defaults.action = categoryname

I also have database table ‘categories’ in which all categories are stored. For example, let’s say the following categories are currently stored in my database:

- html
- css
- js
- php

This means, the following pages exist:

  • mytutorialsite.com/category/html
  • mytutorialsite.com/category/css
  • mytutorialsite.com/category/js
  • mytutorialsite.com/category/php

But when you visit a page with a categoryname that is not listed in the database, like:

  • mytutorialsite.com/category/foo

You should get a 404 Page Does Not Exist message.

How do I achieve that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:43:52+00:00Added an answer on May 17, 2026 at 8:43 pm

    I think you mean with categoryname as action in your route the :categoryname should be used as an action? There are two methods you can use. First is you add only the routes to the router where categories exist. When category/foo is requested the router won’t recognize the route and throw the 404 error.

    The second option is you catch all category/* routes and inside your action you check if the category exists.

    For the first option, add a frontController plugin with a routeStartup function. In this hook you can do:

    public function routeStartup(Zend_Controller_Request_Abstract $request)
    {
        // Get the router
        $router     = Zend_Controller_Front::getInstance()->getRouter();
    
        // Fetch all your categories
        $category   = new Application_Model_Category;
        $categories = $category->fetchAll();
    
        // Loop and add all individual categories as routes
        foreach ($categories as $category) {
            $route  = 'category/:' . $category->name;
            $params = array(
                'module'     => 'default',
                'controller' => 'category',
                'action'     => $category->name
            );
    
            $route = new Zend_Controller_Router_Route($route, $params);
            $router->addRoute($category->name, $route);
        }
    }
    

    The other method is more simple for the route. In your application.ini:

    resources.router.routes.category.route      = "category/:action"
    resources.router.routes.category.module     = "default"
    resources.router.routes.category.controller = "category"
    

    Now all requests from category/SOMETHING will go to the default module, category controller. The dispatcher checks if the action SOMETHING exists. When it does, it executes the action. When not, a Zend_Controller_Action_Exception (“action does not exist”) is throw.

    So in short, both methods work. With the first you get more control. The second is more simple but when e.g. an editAction, addAction or removeAction in the categoryController exist, they can be triggered as well (so be careful with that method).

    PS. Of course, the routeStartup function should have a caching mechanism to prevent a database query on each request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.