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 6856209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:51:23+00:00 2026-05-27T01:51:23+00:00

I am building a Zend Framework site with a conventional directory structure i.e. www.example.com/controller/action

  • 0

I am building a Zend Framework site with a conventional directory structure i.e.

http://www.example.com/controller/action

I would like to insert the country code into the url i.e

http://www.example.com/us/controller/action

I would like to modify the baseUrl to /us so that the Zend Router will strip this off the url and will correctly assign the controller and action. If I do not modify the baseUrl setting, the Zend Router will think that the controller is ‘us’ and the action is ‘controller’.

To achieve this, I tried adding a new function to my bootstrap.php as follows:

    protected  function _initBaseUrl() {


        $region = "us";           
        $front_controller = Zend_Controller_Front::getInstance();

        $request = new Zend_Controller_Request_Http();
        $request->setBaseUrl($request->getBaseUrl() . '/' . $region);

        $front_controller->dispatch($request);
    }

This all works perfectly with standard urls and the Zend Router is able to strip of the country code before determining the route as required.

Unfortunately, it all goes wrong when I add custom routes into the picture. If I create a custom route in the bootstrap.php as follows:

    public function _initRoutes() {

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

    $route = new Zend_Controller_Router_Route(
                    '/local/:place/:index',
                    array(
                        'controller' => 'Local',
                        'action' => 'directory'
                    )
    );
    $router->addRoute('place', $route);
}

I should be able to enter a url like:

http://www.example.com/us/local/dallas/01

and Zend Router should take me to the directory action in the Local controller along with the parameters place = ‘dallas’ and index = ’01’

This, however, throws an error. Removing the /us part of the url throws the same error i.e.

Fatal error: Call to a member function hasResource() on a non-object in C:\vhosts\dev.startyobusiness.com\application\controllers\ErrorController.php on line 49

The ErrorController.php file looks like this:

    public function getLog()
{
    $bootstrap = $this->getInvokeArg('bootstrap');
    if (!$bootstrap->hasResource('Log')) {
        return false;
    }
    $log = $bootstrap->getResource('Log');        
    return $log;
}

where line 49 is the first line of the if statement. I tested the preceding line and

    $bootstrap = $this->getInvokeArg('bootstrap');

returns null for $bootstrap.

It looks to me like I am dispatching the front controller before the custom route is set. Does anyone know the proper way to do this?

  • 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-27T01:51:23+00:00Added an answer on May 27, 2026 at 1:51 am

    You don’t need to strip or do complicated stuff. You can just add a new route. Go to your Bootstrap.php and add this method:

       protected function _initRoutes()
       {
          $Router = Zend_Controller_Front::getInstance()->getRouter();
          $Route = new Zend_Controller_Router_Route(
                          ':language/:controller/:action/*',
                          array(
                              'language' => MAIN_LANGUAGE,
                              'controller' => 'index',
                              'action' => 'index'
                          ),
                          array(
                              'language' => '[a-z]{2}'
                          )
          );
          $Router->addRoute('language-controller-action', $Route);
       }
    

    Note: MAIN_LANGUAGE is a pseudo-costant (I mean it doesn’t exist in PHP) to say the language you like the most

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

Sidebar

Related Questions

I'm building a Q&A site like StackOverflow with Zend Framework. It's all set except
I'm doing this tutorial: http://www.phpeveryday.com/articles/Zend-Framework-Database-Creating-Input-Form-P494.html We are building a simple input form using POST
I'm building my first personal website using Zend 1.11. To create the directory structure
I'm building a paid membership site in php using the Zend Framework. I need
I'm building an application in the Zend Framework, but I'd like to implement a
I would like to build a cms with php using zend framework. I have
I am building a Zend Framework application that performs jobs submitted by the user.
I am building a form in Zend Framework 1.9 using subforms as well as
I'm building a custom autoloader based on Zend Framework's autoloading (related question here ).
I'm building a web application using PHP5.3 and Zend Framework 1.9.4. i have an

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.