1

I have a Controller named Categories and one function in it called index with 1 parameter $cat_id

so it looks like this:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class categories extends CI_Controller {

    function __construct(){
        parent::__construct();
    }

    public function index($cat_id = null){

    }
}

the problem comes when i call it from the browser... i use this:

http://www.mysite.dev/categories/12311323

but returns 404 error page

instead if i use

http://www.mysite.dev/categories/index/12313131

will work fine...

how can i make sure it wont need index in the URL for the index function?

2 Answers 2

6

The default CodeIgniter routing is /controller/function/argument. In order to specify an argument, you need to first specify the function. If you want to specify an argument without the function, you need to define a custom route. Adding this line to your route configuration file should do what you want.

$route['categories/(:num)'] = "categories/index/$1";
Sign up to request clarification or add additional context in comments.

1 Comment

yeah i had this but i forgot to add the /index/... damn i need some sleep
1

What you describe are the default (pre-configured) routes of CI. You can define your own to make the pattern you describe in your question work. See: URI Routing

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.