Page 1 of 1

[Plugin] URL Router

PostPosted: Tue Jan 04, 2011 2:36 pm
by raymond
URL Router Plugin
The URL Router plugin is used to map friendly MVC-style URLs to a Raxan page view. This is accomplished by using special segments within the url path:

URL format:

Here's a break down of the above url format:

page - This represents the name of the web page (without the extension)
view - This represents the page view name to be loaded
param1...paramN - Parameters to be passed to the view.

URL Examples: - will be mapped to - will be mapped to; - will be mapped to;

Sample PHP Code:

class CustomerPage extends RaxanWebPage {

protected function _queryView() {
$param1 = $this->get->textVal(0);
$param2 = $this->get->textVal(1);
$param3 = $this->get->intVal(2);
// do something here

To use the url router plugin download the attached zip file and follow the steps below:

1. Copy url.router.php to raxan/plugins
2. Copy the files index.php and router.htaccess files to your web application root.
3. Rename router.htaccess to .htaccess

Now you're ready to start using friendly url's within your application or web site.

Note: The URL Router plugin requires a web server (e.g. apache) with mod_rewrite or compatible features enabled.

Additional plugin method

* createUrl() - Returns an MVC-style url if friendly url is supported
* createLink() - Returns hyperlink html
* redirectToView()- Redirects the browser to a new pageview

complex usage of router

PostPosted: Fri Sep 28, 2012 10:45 am
by finaxis
Hello, Dear Raymond !

router works great. Since I changed my dir structure, can't make it work. I've been fiddling with router since quite some hours but can't make it to work. Please help decode the mystery.

Code: Select all
 //   - raxan
 //   - app
 //       - app1
 //       - app2
 //   - index.php
 class site_Index_Php extends RaxanWebPage
            function _init()
                if($jsenabled) // ignore checkjs code
                    $this->redirectToView('index');  //else checkjsview
            function _indexView()
                $refer = explode('.', $_SERVER['HTTP_host']); //intended to use with sub-domain
      $host = $refer[1]; //  mapping with folder name like app1
          $url = config('') . config('site.url') . 'app/' . 'app1';
            } // redirects to app1/index.php

// app1
    //- index.php
    //- home.php
    //- member.php
    //- loggedout.php
//  app1/Index.php
    $start = Raxan::loadPlugin('init');

// init plugin
//var_dump(Raxan::config('').Raxan::config('site.url')); outputs :: http://localhost/site/app/app1/
function init()
        $router = Raxan::loadPlugin('url.router');
        foreach (Raxan::config('routes') as $k => $v)      //$config['routes] = array('route.' => 'home','route.logout' => 'logout')
                $k = str_replace('route.', '', $k);
                $router->addRoute('/' . $k, '/' . $v);
        return $router;
    } //loads app1/home.php

//   app1/home.php extends RaxanWebPage
function _indexView()
        $this->redirectTo('loggedout') ; //app1/loggedout.php   

    // BROWSER ERROR - The page isn't redirecting properly
    //Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

intended usage (obviously)
http://localhost/site/app/app1/home/view1/param1 or http://localhost/sites/app/app1/loogedout

Thanks and Regards,

Re: [Plugin] URL Router

PostPosted: Sun Oct 21, 2012 8:37 pm
by raymond
Hi Finaxis,

You can accomplish this by adding the .htaccess file to the app1 and app2 folders. Check out the attached example


Re: [Plugin] URL Router

PostPosted: Fri Nov 16, 2012 8:22 am
by finaxis
Yes, it works perfect even after removing the 'app' folder. now I am using :
----->htaccess for app1
----->index.php for app1
----->htaccess for app2
----->index.php for app2
index.php for root
htaccess for root.

Your trouble shoot is just hitting a bulls eye. No doubt.
Cheers !