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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:26:23+00:00 2026-06-12T03:26:23+00:00

I am trying to test some new features on a live site. My goal

  • 0

I am trying to test some new features on a live site.

My goal is to have a prefix (‘dev’, for example) and have that prefix display the complete site with default actions, except those I define as dev_{action_name}.

Example:

/dev/orders/create

Seeks for OrdersController::dev_create() action, if not found, uses OrdersController::create().

So far, I managed to make a standard ‘dev’ prefix with the Router and put some beforeFilter magic like:

<?php
//bootstrap.php code:
Configure::write('Routing.prefixes', array('admin', 'dev'));

// AppController::beforeFilter() code:
if (preg_match('/^dev_(.*)$/', $this->params['action'], $subs)){
   $new_action = $subs[1];
   if (method_exists($this, $new_action)){
          $this->params['action'] = $new_action;
    } 
}
?>

This works as expected, except the complete Routing schema is not copied to “dev”, which means all the links are rendered without the “dev prefix and my custom routes are disregarded.

I thought about fixing it with .htaccess rule and putting a dev=true in the query string:

#webroot/.htaccess
RewriteRule ^dev(.*)$ index.php?dev=true&%{QUERY_STRING}
#... rewrite conds ...
RewriteRule ^(.*)$ index.php [QSA,L] #original Cake rewrite

But this yielded no results (Cake was still parsing the original URL, not the re-written).

Is there a “right” way of doing 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-06-12T03:26:24+00:00Added an answer on June 12, 2026 at 3:26 am

    I have successfully achieved this with CakePHP 2.2.1. It’s ugly, it’s long, it’s against the rules, but it works! 😀

    file: /app/webroot/.htaccess

    RewriteEngine On
    RewriteRule ^dev/(.*)$ $1 //my hack
        //      /dev/orders/create => /orders/create 
        //      /dev/css/main.css => /css/main.css
        // This only changes the url for the next rule
        // Cake would have still parsed /dev/orders/create
        // but this is needed for the sake of static files in app/webroot
    //cake native rewrite
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
    

    file: bootstrap.php

    $url = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : ''; 
        //$url is still /dev/orders/create, despite the rewrites
    
    Configure::write('App.dev', false); 
    //we use this to check if we're in "dev" mode
    //anywhere in the app, just call: 
        //  if ( Configure::read('App.dev') ) ...
    
    //check if URL starts with /dev
    if (preg_match('|^/dev|', $url)){ 
        /* the most important thing is to trick CakePHP
        into thinking it's on a /dev/ subfolder on the server
        this preserves all the routing as it 
                should be, not making it prefixed route */
        Configure::write('App.base', '/dev');
        Configure::write('App.dev', true);
        //this changes /dev/orders/create to /orders/create 
                //for Cake's Route parser
        $_SERVER['REQUEST_URI'] = preg_replace('|/dev|', '', $_SERVER['REQUEST_URI']); 
    }
    ?>
    

    At this point, we have all that we need to have CakePHP display a complete copy of the site under /dev/.
    Cake does all the default actions+views, all links work as expected (as long as you use helpers for URLs), all static files get served.
    All app paths and constants remain intact.

    Now for some method magic:

    <?php
    //file: AppController.php
    public function invokeAction(CakeRequest $request) {
    
        if (Configure::read('App.dev')) {
            $new_action = 'dev'.$request->params['action'];
            if (method_exists($this, $new_action)){
                $request->params['action'] = $new_action;
            }
        }
    
    
        return parent::invokeAction($request);
    }
    ?>
    

    All of this enables us to:

    • Have a complete working alias of the site on /dev/, which includes routes, prefixes, static files, database connections, etc.
    • Override an ACTION using “dev” in front of the name.
    • Have a single switch for “dev” or “not dev” (App.dev config)

    For instance:

    <?php
    //OrdersController.php
    
    //gets called on /admin/orders/view
    public function admin_view(){} 
    
    //gets called on /dev/admin/orders/view
    public function devadmin_view(){ 
        //views have to be defined manually for DEV actions
        $this->render('devadmin_view'); 
    }
    
    //gets called on /admin/orders/add 
    //            AND /dev/admin/orders/add
    public function admin_add() {} 
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying some iOS test applications on the new Mac mini, that supports Bluetooth
I am new to Haskell and trying to fiddle with some test cases I
I am trying to test some methods in my models. For example, in my
I want to test some features that needs delayed jobs to work, on cucumber.
I am new to testing so I am trying to test some random things
I'm trying to unit-test some classes that make use of a Singleton class whose
Ok, so I'm trying to Unit test some GUI elements I have a JButton
I am new to unit testing and I am trying to test some of
I am currently trying to test some code I have in a web application
Im using the Prism/Composite Application Library and trying to unit test some code that

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.