• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Json" as controller name does not work

#1
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?

//Life motto
if (sad() == true) {
     sad().stop();
     develop();
}
Reply

#2
Strange I just ran it with CodeIgniter 3.1.11 with no errors without using routes.

Maybe something to do with your routing.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
(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.

//Life motto
if (sad() == true) {
     sad().stop();
     develop();
}
Reply

#4
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'
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.