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

  • SEARCH
  • Home
  • 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 7985455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:33:37+00:00 2026-06-04T11:33:37+00:00

I searched on Google, and I got this code to check if a controller

  • 0

I searched on Google, and I got this code to check if a controller exists or not.

$front = Zend_Controller_Front::getInstance();
if ($front->getDispatcher()->isDispatchable($request)) {
    // Controller exists
}

But I don’t know where I should put this code. What is $request?
I’m in Boostrap.php. I have _initRoute, I need to check if a controller doesn’t exist, if it doesn’t then I will add a new route.


Updated after first answer. I have some routes in Boostrap.php

public function _initRoute() {


    $front = Zend_Controller_Front::getInstance();
    $router = $front->getRouter();
    $router->addRoute(
        'username',
        new Zend_Controller_Router_Route(':username',
            array('controller'=>'profile',
                  'action'=>'index')
        )
    );

    $router->addRoute(
        'username/sets',
        new Zend_Controller_Router_Route(':username/sets',
            array('controller'=>'profile',
                  'action'=>'sets')
        )
    );


}

This Routes, will make mydomain.com/{username} show content same as mydomain.com/profile/index/username/{username}

But the problem is, when I type mydomain.com/{anything or any controller} , it routes as I define on Boostrap. So, I think, I need to check the controller is existing or not, if it doesn’t then do the routes.

Am I wrong? After first answer, I added the plugin, and put it under _initPlugin to register it. But look like it not work.

This is my boostrap file:

<?php


//Zend_View_Helper_PaginationControl::setDefaultViewPartial('paginator.phtml');

class Plugin_MyX extends Zend_Controller_Plugin_Abstract {
    public function routeStartup(Zend_Controller_Request_Abstract $request) {
        $front = Zend_Controller_Front::getInstance();
        $dispatcher = $front->getDispatcher();

        if (!$dispatcher->isDispatchable($request)) {

            $front = Zend_Controller_Front::getInstance();
            $router = $front->getRouter();
            $router->addRoute(
                'username',
                new Zend_Controller_Router_Route(':username',
                    array('controller'=>'profile',
                          'action'=>'index')
                )
            );

            $router->addRoute(
                'username/sets',
                new Zend_Controller_Router_Route(':username/sets',
                    array('controller'=>'profile',
                          'action'=>'sets')
                )
            );


        } else {
            // exist
        }



    }


}




class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{


    protected function _initPlugin() {
        $front = Zend_Controller_Front::getInstance();
        $front->registerPlugin(new Plugin_MyX());
    }

    public function _initRoute() {


    }


}
  • 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-06-04T11:33:38+00:00Added an answer on June 4, 2026 at 11:33 am

    You should put that code in a Controller Plugin since the request object does not yet exist at bootstrap time.

    The $request variable in question is an object of Zend_Controller_Request_Http. This object is initially created when the front controller goes to dispatch a request.

    You could register a routeStartup plugin and place the code there. That would be the earliest point at which you can use the Request object. All controller plugin chains will pass the request object to your plugin except for dispatchLoopShutdown().

    Here is sample plugin code:

    class Application_Plugin_Example
    {
        public function routeStartup(Zend_Controller_Request_Abstract $request)
        {
            $front = Zend_Controller_Front::getInstance();
            if ($front->getDispatcher()->isDispatchable($request)) {
                // Controller exists
            }
        }
    }
    

    If you are trying to just handle 404 errors, this is what the ErrorHandler plugin can be used for this purpose.

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

Sidebar

Related Questions

I've searched google and SO for a solution to this problem but have not
I searched for this subject on Google and got some website about an experts
I searched Google on how to do this, and I got the following link:
I got this message when doing some javascript programming, and after some google searches,
I have searched around Google and StackOverflow trying to find a solution to this,
ive searched this question on google and i've found many answers but none of
I searched SO and google and saw only problems while doing this, unfortunately for
I've searched (Google and forums) and I still can not find an answer to
I searched Google search APIs and didn't find a way to get a website
I've searched Google for awhile now, doesn't seem like I am correctly searching it

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.