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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:44:54+00:00 2026-06-15T23:44:54+00:00

I love the way SO handles URIs. I’d like to mimic the same behaviour

  • 0

I love the way SO handles URIs. I’d like to mimic the same behaviour in CI. I have a controller called Users and the index method should take one argument, that being the user ID. I search the DB for the username associated with that user ID. Consider that user:1 has username:Santa Claus, how can I append the username to the URI, so that it looks like http://foo.com/users/1/santa-claus

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Users extends CI_Controller {

function index($uID = 0) {
    if ($uID > 0) {
        $this->load->model('users_model');
        $uname = $this->users_model->_getUsername($uID);

        #append somehow..       

    } else {
        echo('load all users');
    }
}

}

Just to be clear, I’m trying to achieve this:

https://stackoverflow.com/a/11041075/704015

  • 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-15T23:44:54+00:00Added an answer on June 15, 2026 at 11:44 pm

    application/config/routes.php

    $route['users/(:num)/(:any)'] = 'users/index/$1';
    

    Controller

        function index($uID = 0) {
             .....
             $uname = strtolower(str_replace(" ", "-", $uname));
    
             header("Location: ".base_url()."user/".$uID."/".$uname);
    

    Please include a condition do something else incase username is already present to avoid loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I love the way StackOverflow handles tags. Is there any jQuery plugin that would
boost::bind handles boost::shared_ptr the same way as raw pointers. QObject * object(new QObject); boost::shared_ptr<QObject>
I have a method that is called when an exception is thrown. Only the
I really love the way foursquare designed venue detail view. Especially the map with
I am in love with Netbeans Source->Format feature. Is there any way to get
I love my GUID. However, lately I have been doing some research to understand
I love paredit. But there are a couple of things I hate, and have
I love NHibernate's ability to have one table to store multiple types based on
I've just started using Git and I love it, but I have had an
I have three Entity Objects. The relationship between these entities is kinda love triangle!

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.