0

I have my codeigniter setup with a default controller. It's accessible as follows:

site.com/index.php 

But it's actually:

site.com/project/index

Where index is the default function.

I would like to do the following:

site.com/project7362

But it actually wants:

site.com/project/index/project7362

Where project name is a variable that is pass into the index function. But by default it looks for project-name as a controller. Is there a way to avoid this?

Essentially what I'm hoping to accomplish is to pass a variable directly after the domain name. A user may create a project, and I want that project to be accessible at domain.com/project_id

2
  • Hello Adam, what is name of your controller that you are trying to use? Please also edit project and project-name more clearly so it is understandable what you want to achieve. Commented Nov 9, 2014 at 17:39
  • The name of my controller is "project". Do my edits make more sense? Commented Nov 9, 2014 at 19:44

1 Answer 1

1

"Essentially what I'm hoping to accomplish is to pass a variable directly after the domain name. A user may create a project, and I want that project to be accessible at domain.com/project_id"

so another way to do this would be to have it like.

domain.com/project/id

this will give you much more flexibility later in your routes for adding different features.
in config/routes:

$route['project/(:any)'] = 'project/view/$1'; 

in your project controller

    function view($id) {

    // clean it
    $id = htmlspecialchars($id) ;

   if ( ! $project = $this->members->returnProjectBy($id) {

       $this->showNoResultsFor($id) ; } 

   else { $this->show($project) ;  } 

   }    

OR -- another way to do this would be to put your defined routes first, and then have project be last (because it requires searching on whatever is there)

$route['home'] = 'page/home'; 
$route['contact'] = 'contact'; 
// etc etc so you first define your hard coded routes, and then if its not any of those
// you do a search on whatever the value is to find a project 
$route['(:any)'] = 'project/view/$1';

so then your link could be

domain.com/id
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.