Welcome Guest, Not a member yet? Register   Sign In
Vanity URL's - one small question! (detecting methods)
#1

[eluser]Unknown[/eluser]
Hey, as you can probably tell, I am relatively new to CodeIgniter.

I have written this extension to the CI_Router class, named MY_Router and placed in the 'core' folder in the applications folder.

Code:
class MY_Router extends CI_Router {
function __construct()
{
  parent::__construct();
}

function _validate_request($segments)
{
  if (!file_exists(APPPATH . 'controllers/' . $segments[0] . EXT) && !is_dir(APPPATH . 'controllers/' . $segments[0]))
  {
   if (count($segments) === 1)
    return array('users', 'get_user', $segments[0]);
   else if (count($segments) > 1)
   {
    $user = array_shift($segments);
    $func = array_shift($segments);
    $start = array('users', $func, $user);
    if (count($segments) > 0)
     return array_merge($start, $segments);
    else
     return $start;
   }
  }
  return parent::_validate_request($segments);
}
}

What this code does is it enables you to use a 'Vanity URL' and also have a function appear after it, so if you had example.com/username/blog it would bring you to the users blog page, and if you went example.com/username/blog/blogID it would show relative information.

Now here lies my problem.

if you enter example.com/username/bloog it will return a 404 error.

Does anyone have any ideas on how to detect if the method exists and redirecting to the users profile if it doesn't?

It's got me completely stuck (I think I used my limited brain power figuring out how to write the little bit of code I did!)




Theme © iAndrew 2016 - Forum software by © MyBB