1

i have a class called comment and inside i have 3 functions called __construct, index and getComments

Class comment extends CI_Controller
{
   public function __construct(){
      parent::__construct();
   }

   public function index($comment_id){
      echo $comment_id;
   }

   public function getComments(){
      //do stuff to get comments and print them to screen
   }
}

also in my routes folder i have added a new route

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

so when i go to mysite.com/comment/123131313123

it echos the comment id but when i do an ajax call to the getComments() function in the same class it wont work and instead it will show me the word "getComments"

how can i make sure that when i go direct to the index function it will show me the parameter and also be able to do ajax calls without having any other problem with the other functions?

Thanks.

2
  • How are you doing the ajax call? What's the URL you're using? Commented Feb 1, 2012 at 17:04
  • im using mysite.com/comment/getComments - i have not added the php code i use for the ajax calls becuase its too many... if i remove the index and the route all the ajax calls work fine. Commented Feb 1, 2012 at 17:13

1 Answer 1

2

mysite.com/comment/getComments is getting matched to your route

You need to make another route before it which explicitly matches your ajax action

$route['comment/getComments'] = "comment/getComments";
$route['comment/(:any)'] = "comment/index/$1";

Routes are run in the order they are defined.

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

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.