User Specific Portal Module - Url Management

Hi everyone,

I’m having some trouble trying to implement something with URL management and would like some advice etc. on how to accomplish it.

I’ve created a portal module which is intended to display a mini-site for each user - each user will use my content management system to create a mini-website.

At the moment I have


/portal/1 

which displays the page with id = 1. What I want to have instead is:


/user-slug/page-slug

/portal/user-slug/page-slug

Where user-slug is the user’s first and last name and page-slug is the page id + title.

The part that I’m not sure on, is how to make sure that the user-slug gets set as the first parameter of the URL and that all links generated by the url manager to urls within the portal module have this user-slug prepended at the beginning.

If the user-slug isn’t set, I’d like to be able to redirect to the page for the logged in user. I’ll also need to be able to retrieve the user id.

Links to pages outside of the module should not have the user-slug in the URL. I also want this to work with controllers so I can have controllers/actions within the module as well as displaying the user generated content.

I got as far as extending CUrlManager with the following (which added the slug to all links):


<?php


class WebCUrlManager extends CUrlManager

{       

    public function createUrl($route,$params=array(),$ampersand='&')

    {

        if (!isset($params['user-slug']) ) 

        {

            $params['user-slug']=Yii::app()->user->id;     

        }

        return parent::createUrl($route, $params, $ampersand);

    }

}

Performance isn’t too much of an issue because the site requires authentication and low user numbers (100s).

I’ve done quite a bit with URL management before - url paths, using slugs for SEO friendly URLs etc. but I have no have no idea how to accomplish this.