Welcome Guest, Not a member yet? Register   Sign In
Hitting a wall with Routing
#1

[eluser]ywftdg[/eluser]
Hey guys, I have been trying all day today to understand routes, and I just do not get it. For example, I am trying to remove the parent controller name from my url. My parent controller is called commonwealth, so my urls end up like commonwealth/projects/ and commonwealth/projects_details/1

1) I am trying to remove commonwealth from the url.
2) I am trying to remove the id (pId) number at the end, and instead show the project name (pTitle)

If anyone has any time and knowledge with this, could they lend me some help, I am having a hell of a time..
#2

[eluser]ywftdg[/eluser]
Ok, I have since fixed this, it all came very fast, hahah. But I have a few questions on best methods.

So now, in order for this to work, I have my urls going: domain.com/projects/1/name
Is this url still nice, ok, clean if it has the number in the middle like that? Also, if I have names with spaces, and I get the formating thing, is this garbage too, should be fixed. I think wordpress uses like - to make spaces yeah?

Let me know what you guys think...


Ignore posts above, all working and fine. In case anyone in the future is searching this forum for routes, url spaces, I fixed my problems above doing:

Added my remapping routes in the 'application/config/routes.php' file to the following:
Code:
$route['projects/:num/:any'] = "commonwealth/projects_details/";
$route['projects'] = "commonwealth/projects/";

The first one still included my project id, but then adds the name (or anything you want) at the end of my url. I then needed to remove any spaces that might occur at the end of my urls (project names sometimes have spaces).
Code:
<? $newTitle = str_replace(" ","-", $row->pTitle);?>
The second route removed my main controller as well (commonwealth) from the url.

Then when making links in my views, i just call the /projects area. I also removed the spaces. Maybe this will help another beginner somewhere in the future..

I did the above because I wanted a clean url structure to my clients portfolio. So "domain.com/projects/1/sears_tower " would be an example.
#3

[eluser]neen[/eluser]
Or you could just do:

$route['projects/:any'] = 'commonwealth/projects_details/';
$route['projects'] = 'commonwealth/projects/';

Then in your controller:

projects_details($title) {

// lookup title, render view, etc
}




Theme © iAndrew 2016 - Forum software by © MyBB