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

Controller classes must exist as files (why??) #6240

Open
uuf6429 opened this issue Sep 3, 2023 · 0 comments
Open

Controller classes must exist as files (why??) #6240

uuf6429 opened this issue Sep 3, 2023 · 0 comments

Comments

@uuf6429
Copy link

uuf6429 commented Sep 3, 2023

CI is relatively flexible, there's just one tiny major problem:

https://github.com/bcit-ci/CodeIgniter/blob/63d037565dd782795021dcbd3b1ca6f8c8a509e4/system/core/CodeIgniter.php#L355...L361

If a (custom) router returns controller classes that have already been loaded, but perhaps from a different location/namespace, there's no way to make it work. This seems like a very silly limitation.

The code referenced above shouldn't even be loading the class from the filesystem, let alone constructing some file path out of a class name. At the very least, this whole default logic would only make sense after checking class_exists().


In short, here's some backward-compatible improved version:

	if (empty($class))
	{
		$e404 = TRUE;
	}
	else
	{
		if (!class_exists($class) && file_exists(APPPATH.'controllers/'.$RTR->directory.$class.'.php') ) {
			require_once(APPPATH.'controllers/'.$RTR->directory.$class.'.php');
		}

PS: class_exists triggers autoloading, in the right scenario, thus avoid the rest of the file-checking-file-loading code.

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

1 participant