Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
616 views
in Technique[技术] by (71.8m points)

php - default controller inside subfolder codeigniter 3 not working

In codeigniter 3 application i have directory structure like this:

-Myproject
  -application
    -controllers
     -home
       Welcome.php   //This is my controller inside home directory

How to set Welcome controller as default controller? I use below code

$route['default_controller'] = 'home/Welcome';

This routing works for previous versions of codeigniter.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

By default, you are not allowed to do that. To get around this, you need to hack your system Router.php:

codeigniter/system/core/Router.php

Edit a few lines of code so that it becomes like this:

codeigniter/system/router.php

line 1. if (!sscanf($this->default_controller, '%[^/]/%[^/]/%s', $directory, $class, $method) !== 2)

line 2. if ( ! file_exists(APPPATH.'controllers'. DIRECTORY_SEPARATOR . $directory. DIRECTORY_SEPARATOR .ucfirst($class).'.php'))

line 3. $this->set_directory($directory);

Once you've done, you can call the default controller under directory.

$route['default_controller'] = 'home/Welcome';


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...