-1

I have one controller Leads & there are two function

  1. Index
  2. lead-details

Here is my code

class Leads extends CI_Controller {
  public function index(){}
  public function lead_details($slug){}

Its working like below

www.mysite.com/leads/    This will access to index function
www.mysite.com/leads/lead_details/nice-not-to-have-2

Now i want to get the details like

www.mysite.com/leads/nice-not-to-have-2

I tried this but it confuses with index function

$route['leads/(:any)']  = 'leads/lead_details'

Note: This is not duplicate of this

Issue is with index function. How i can do it with application/config/routes.php?

Example: leads/index give me error as it points to lead_details function

2 Answers 2

0

Correct like below:

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

A URL with leads as the first segment, and anything in the second will be remapped to the leads class/controller and the lead_details method/function.

If you type :

  • Either yoursite.com/leads or yoursite.com/leads/index, it will route to index function of leads class.
  • yoursite.com/leads/nice-not-to-have-2 to leads/lead_details

Tested on CI_VERSION : '3.0-dev'

Sign up to request clarification or add additional context in comments.

2 Comments

Then what difference in www.mysite.com/leads/nice-not-to-have-2 AND www.mysite.com/leads/index...here index is function name
www.mysite.com/leads/index give me error then as it points to lead_details function
0

if you want to to be route your controller function go to config->routes.php than settlement your routes here like this $route['routename'] = 'leads/leads-details'; #url function

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.