Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem throw error for default controller #146

Closed
arma7x opened this issue Jul 5, 2016 · 11 comments
Closed

Problem throw error for default controller #146

arma7x opened this issue Jul 5, 2016 · 11 comments

Comments

@arma7x
Copy link
Contributor

arma7x commented Jul 5, 2016

  1. Problem for routing without using namespace:
    case-1 = $routes->add('', 'Home::index') $this->controller has value of Home, result OK
    case-2 = $routes->add('/', 'Home::index') $this->controller has value of \Home, result ErrorException line 500
  2. Problem for routing with namespace
    case-1 = $routes->add('/', 'Home::index', ['namespace'=>'App\Controllers']) $this->controller has value of \App\Controllers\Home, result ErrorException line 500

What does line 500 really do in /system/Controller.php.

@arma7x arma7x changed the title Throw error when set $routes->setDefaultNamespace(App\Controllers) Throw error for default controller Jul 5, 2016
@arma7x arma7x changed the title Throw error for default controller Probel throw error for default controller Jul 5, 2016
@arma7x arma7x changed the title Probel throw error for default controller Problem throw error for default controller Jul 5, 2016
@lonnieezell
Copy link
Member

There is no line 500 in system/Controller. I'm going to guess that was actually in system/CodeIgniter.php, since that area has to do with booting the controller up.

With the very latest code, I'm not getting any errors during these scenarios, but I did fix one or two smaller issues with routing last night, so that might be why.

Can you try again with the latest code and see if you're still getting the same issue?

@arma7x
Copy link
Contributor Author

arma7x commented Jul 6, 2016

Ye, that was actually in system/CodeIgniter.php line 500 ;
include APPPATH.'Controllers/'.$this->router->directory().$this->controller.'.php';
I have latest code from github and still have this problem.

@lonnieezell
Copy link
Member

I just made another push that, on my system, allows me to auto-route with or without namespaces. Can you check yours?

If it doesn't work, please provide details on your server, OS, etc.

@arma7x
Copy link
Contributor Author

arma7x commented Jul 6, 2016

Linux i686 Lubuntu 16.04, php 7.0.4 and Codeigniter4(branch::develop).
Error Throw:
ErrorException
include(/home/xxxxx/CodeIgniter4/application/Controllers/\App\Controllers\Home.php): failed to open stream: No such file or directory

@lonnieezell
Copy link
Member

Hm. Could you describe your app setup in detail? Here's mine, which should match the defaults currently:

  • Routes.php - defaultNamespace = 'App\Controllers'
  • Routes.php - autoRoute = true
  • Routes.php - $routes->add('/', 'Home::index');
  • Home Controller - namespace = App\Controllers
  • .htaccess file in place.
  • Accessing /, /home, or /home/index all work for me

@lonnieezell
Copy link
Member

Oh - and what file/line is giving that error now?

@arma7x
Copy link
Contributor Author

arma7x commented Jul 6, 2016

Its solve now, changes commit 60effd6 have fixed this issues, Thanks.
Does auto-routing in sub-folders works?
Now, I get new error if route to controller that does not exist like http://127.0.0.1:2000/blog. It should trigger 404 but again throw error exception:
ErrorException
include(/home/xxxxx/CodeIgniter4/application/Controllers/Blog.php): failed to open stream: No such file or directory

BASEPATH/Router/Router.php at line 406

@lonnieezell
Copy link
Member

Non-namespaced auto-routing in sub-folders should be working now, yes.

Good point about the non-existing controllers. I was so focused on getting everything else to work, I forgot a basic check to see if the file existed first. Doh!

@arma7x
Copy link
Contributor Author

arma7x commented Jul 6, 2016

Non-namespaced auto-routing in sub-folders still not works. In method autoRoute(), line 405, $this->directory does not determine the directory of specific file. Before set first segment to be the controller, I think it should determine whether the first segment is sub-folder or controller;
http://127.0.0.1:2000/home does return Home as controller -> OK
http://127.0.0.1:2000/home/index does return Home as controller -> OK
http://127.0.0.1:2000/subfolder/home does return Subfolder as controller -> 404
http://127.0.0.1:2000/subfolder/home/index does return Subfolder as controller -> 404

@arma7x
Copy link
Contributor Author

arma7x commented Jul 6, 2016

In method validateRequest(), line 444 :
is_dir(APPPATH.'Controllers/'.$this->directory.$segments[0])
The $segments[0] should be ucfirst($segments[0]) for linux os, or will return false if sub-folder name style is ucfirst.
I change those, and auto-routing in sub-folders seem works now.

@lonnieezell
Copy link
Member

Good catch. Fixed in 3562895

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants