-1

I have a CodeIgniter website and the link structure for the inner pages look like below:

http://www.example.com/pages/Campus-Tour/18/3

pages is my controller name and campus-tour, 18 and 3 are the values passed into the index method.

I want to make a pretty url, so can I use something like this in routes.php?

$route['campus-life/campus-tour'] = 'pages/Campus-Tour/18/3';

to show this URL "http://www.example.com/campus-life/campus-tour"

Vickel
  • 7,879
  • 6
  • 35
  • 56
Abhi
  • 11
  • 1

3 Answers3

0

Please use this syntax for routing.

$route['string-that-you-want-to-show-in-url'] = 'controller/function/arg1/arg2';

Example --

$route['campus-life/campus-tour'] = 'pages/campus_tour/$1/$2';

Note:- PHP doesn't support hyphen(-) inside function name, your function name (Campus-Tour) is invalid, please check it & use the above syntax.

Sorav Garg
  • 1,116
  • 1
  • 9
  • 26
0

FYI: A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.


If you transmit data URL with this to pages/Campus-Tour/18/3 this campus-life/campus-tour it's clearly missing your URL parameter as you can see.

What you can do is <form> submit with POST and in the function, you can catch those.

In View

<form action ="campus-life/campus-tour" method ="post">
    <input type="hidden" name="first_param" value = "18"/>
    <input type="hidden" name="second_param" value = "3"/>
    <input type="submit"> # make this a No button. Should looks like <a> tag. Use CSS. (check Link)
</form>

In Controller

function Name() #add valid function/controller name
{
    # catch the POST values
}

Reference : How to make a button look like a link?

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

Following is the syntax for routing. Please use this:

$route['pages/Campus-Tour/(:any)/(:any)'] = 'pages/campus-tour/$1/$2';
Vickel
  • 7,879
  • 6
  • 35
  • 56
PHP Geek
  • 3,949
  • 1
  • 16
  • 32