Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /dev/orders/create
- <?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;
- }
- }
- ?>
- #webroot/.htaccess
- RewriteRule ^dev(.*)$ index.php?dev=true&%{QUERY_STRING}
- #... rewrite conds ...
- RewriteRule ^(.*)$ index.php [QSA,L] #original Cake rewrite
- // need to override invokeAction
- public function invokeAction(CakeRequest $request) {
- if ($request->prefix == 'dev') {
- if (!method_exists($request->action)) {
- $request->action = str_replace($request->prefix.'_', '', $request->action);
- $request->prefix = null;
- }
- }
- return parent::invokeAction($request);
- }
- 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]
- $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']);
- }
- ?>
- <?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);
- }
- ?>
- <?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() {}
- ?>
Add Comment
Please, Sign In to add comment