EllisLab text mark
Advanced Search
     
CI finding method in other controllers but not my News one
Posted: 04 October 2012 09:19 PM   [ Ignore ]
Avatar
Joined: 2012-08-20
64 posts

If I put any method in my News controller other than index(), the site won’t find it through the URL. No other controller seems to have this problem. I’ll demonstrate:

This is temp.php and it displays “got here” on the page when I go to “http://www.mydomainhere.com/temp/rate”:

class Temp extends MY_Controller {

   
public function rate() print "got here"}


This is news.php and I get a 404 error when I go to “http://www.mydomainhere.com/news/rate”:

class News extends MY_Controller {

public function rate() print "got here"}

public function index() print "we're in index"}


If I go to “http://www.mydomainhere.com/news” “we’re in index” is displayed.

As a test, I changed News so it is extending CI_Controller directly. Nothing changed.


Any ideas on what could be going on?

 
Posted: 04 October 2012 10:44 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2010-06-27
134 posts

you could try putting a entry in the config/routes.php file like this and see if it help:

$route['news/rate'"news/rate"

i find it weird too that some times the default routing code does not work quite right, but when i put a entry in the routes.php file it works proper.

but sometimes it works without setting a route entry.

 Signature 

“I Reject Your Reality and Substitute My Own” - Adam Savage, M5 Inc

 
Posted: 05 October 2012 11:29 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2012-08-20
64 posts

Ah, ha! Here’s what’s wrong. I looked in routes and saw this:

$route['news/create''news/create';
$route['news/(:any)''news/view/$1';
$route['news''news'

I deleted all that and, vola, my method started working.

I forgot that I put that stuff in there when I was doing the CI tutorials. Thanks Rolly! I’d have never thought to look there had you not mentioned it.