如何最好地实现数据库驱动的动态URL /控制器名称?

I have a website that is written in PHP on codeigniter. The scenario I am looking to cope with is the following:

When a user signs up, Their personalised homepage should appear at www.mysite.com/username. Other urls are of the form www.mysite.com/username/pictures & www.mysite.com/username/videos.

So basically what I need is www.mysite.com/username/method (where username is database driven) should always hit the same controller, if the username exists in the database.

Currently, what I am doing is I am using the custom 404 controller to do this. If a URL reaches the custom 404 controller, I check if the controller name matches a username in the data base, then checking the method name and calling the required method. Like so:

$this->load->model('school_model');
        $this->load->model('event_model');

        $this->load->helper('apps_helper');

        $controllerName = $this->uri->segment(CONTROLLER);
        $controllerMatch = $this->school_model->findSchoolByUid($controllerName);
        $this->data['controller'] = $controllerMatch;

        if($controllerMatch != false){
            $methodName = $this->uri->segment(METHOD);
            if($methodName === "something"){
            //Do something
            }
            if($methodName === "something else"){
            //Do something else
            }
            if($methodName === "another thing"){
            //Do another thing
            }
            if($methodName === "last thing"){
            //Do last thing
            }
            ...
        }
        else{
            //Load 404 page
            $this->output->set_status_header('404');
            $data['content404'] = true; 
            $this->load->view("common/header", $data);
            $this->load->view('frontend/index404', $this->data);
            $this->load->view("common/footer");
        }

My query is, is this the best way to go about what I need ? How can I improve this ? I have heard of the HMVC modular extension for codeiginiter which may be a good bet ? Just looking for some advice.

You can do this by writing this code in your config > routs.php file

$route['(:any)/pictures'] = 'yourcontrollername/functionName/$1';

now in this if any one write username/pictures url than it will automatically goes to your controller.