Welcome Guest, Not a member yet? Register   Sign In
uri routing problem
#1

[eluser]dhananjay[/eluser]
my client wants this type of url structure in codeigniter i am unable to find out solution on this, this is possible to achieve or not

- Freight Search pages: www.freightmatch.com.au/freight/
- Internal Freight pages: www.freightmatch.com.au/freight/transport-[origin]-to-[destination]/[Freight-ID]

now first url will show listing of freight jobs and second url will be for each single job but because both have 'freight' in url so i am unable to understand how can i route them to different methods....

now if for this i create index method www.freightmatch.com.au/freight/

this will work on index
so route will be

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

it can also have www.freightmatch.com.au/freight/10

with pagination links now about second

Internal Freight pages: www.freightmatch.com.au/freight/transport-[origin]-to-[destination]/[Freight-ID]

how would i know that with same url it is different page now ?

that's my problem any help would be appreciated....
#2

[eluser]InsiteFX[/eluser]
And where are they getting the [origin] and [destination] from ?

If the freight-id is numeric then you could check for that, otherwise you would need to break it down using the uri_segment

#3

[eluser]dhananjay[/eluser]
origin and destination will be strings and they will be different for each url , yes frightid will be numeric...

also so breaking my uri segment mean i will need to handle both in same index function...they can't be handled by other controller or method by defining route[]


Thanks
#4

[eluser]CroNiX[/eluser]
You can't do everything you are asking using only one method. However, using routes, the methods are invisible to the user, so it shouldn't be a problem.

Code:
// http://www.freightmatch.com.au/freight/transport-[origin]-to-[destination]/[Freight-ID]
$route['freight/transport-(.*)-to-(.*)/(:num)'] = 'freight/view_transport/$1/$2/$3';

// http://www.freightmatch.com.au/freight/transport-[origin]-to-[destination]
$route['freight/transport-(.*)-to-(.*)'] = 'freight/view_transport/$1/$2';

// http://www.freightmatch.com.au/freight/20
$route['freight/(:num)'] = 'freight/index/$1';

// http://www.freightmatch.com.au/freight
$route['freight'] = 'freight'; //probably don't need this one
For the first 2, create a new method to view_transport
Code:
function view_transport($origin, $destination, $freight_id = null)
{
  echo "Origin: $origin<br>";
  echo "Destination: $destination<br>";
  if (is_null($freight_id))
  {
    //Freight_id not submitted, just use origin/destination
  }
  else
  {
    //FreightID also submitted
    echo "FreightID: $freight_id";
  }
}
#5

[eluser]dhananjay[/eluser]
Thanks a lot this worked seamlessly , Thank You

i have another question too if you can help with that too

i have a custom 404 page now when some pages do not exists in database i am redirecting user to that 404 page now i want to make sure that robots will also see this as 404 page but i didn't found what i will need to for that ....so the page i have, is dealt by bots as 404 error page....
#6

[eluser]CroNiX[/eluser]
instead of redirecting, which changes the url, use show_404(); which will show the 404 page with the 404 header and keep the non-existing url intact so spiders will see that.
#7

[eluser]dhananjay[/eluser]
Yay, thanks a lot...
#8

[eluser]dhananjay[/eluser]
Now the problem is after doing this that it shows default 404 page of codeigniter but not the one i have defined in route file

i.e. $route['404_override'] = 'error404';
#9

[eluser]Tpojka[/eluser]
Maybe to change the code in application/errors/error_404.php?
#10

[eluser]dhananjay[/eluser]
$route['404_override'] = 'error404';

error404 is a controller which shows a page that contain header and footer of my website and shows that page is not found in that file application/errors/error_404.php?

i will not be able to call view file..would i?




Theme © iAndrew 2016 - Forum software by © MyBB