CodeIgniter Forums

Full Version: "Json" as controller name does not work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Well i've faced a very weird issue.

If i create a controller named "Json" and try to access it i get an "Object not found" error in my CI project. On the other hand if i give the controller another name it'll work like a charm or if i use an Uppercase first letter it will also work.

Here's my controller, filename and routes files.

Json.php
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Json extends CI_Controller {
 public function 
index(){
   
// Some code
 
}


Routes.php
PHP Code:
$route['(?i)json']              'json';
$route['(?i)json/(:any)']       'json/$1'

Any ideas?
Strange I just ran it with CodeIgniter 3.1.11 with no errors without using routes.

Maybe something to do with your routing.
(10-29-2019, 03:42 AM)InsiteFX Wrote: [ -> ]Strange I just ran it with CodeIgniter 3.1.11 with no errors without using routes.

Maybe something to do with your routing.

Well my full routing file is: 

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

$route['xml']                   'xml';
$route['xml/(:any)']            'xml/$1';

$route['json']                  'json';
$route['json/(:any)']           'json/$1';

$route['dashboard']             'members';
$route['account']               'members/account';
$route['login']                 'members/login';
$route['register']              'members/register';

$route['members']               'members';
$route['members/(:any)']        'members/$1';

$route['(:any)']                'pages/$1';

$route['default_controller']    'pages';

$route['404_override']          '';
$route['translate_uri_dashes']  FALSE

I' ll check if there's something wrong with the .htaccess file.
The following isn't very useful because it basically asks that you follow CI's normal controller/method/arg URI relationship

PHP Code:
$route['json/(:any)']  'json/$1' 

In other words, you're not actually remapping anything.

You really need to know which method you want to run and put that in the value. For instance, if you want it all to go to index().

PHP Code:
$route['json/(:any)']  'json/index/$1' 

Naturally, index() would need to accept arguments, i.e..

PHP Code:
class Json extends CI_Controller {
 public function 
index($arg null){
  // Some code
 
}


Notice that index has an optional argument. If you add that then you don't need this route.

PHP Code:
$route['json'] = 'json'