Pregunta

Scenario

I have a website which I am upgrading to the current development version of CodeIgniter 3. I have followed the upgrade instructions to rename all class files to be uppercase first (e.g. application/controllers/Home.php)

Expected Outcome

For lowercase URLs to use the controllers as normal, for example:

http://examplesite.com/home/

to use the Home.php controller.

What I Got

The uppercase filenames are not automatically being called when the url has a lowercase first letter. (A 404 error).

I Have Tried

  • Typing in the URL with an uppercase first letter for the controller, ie. http://examplesite.com/Home/ This produces the controller as expected.
  • Uppercasing the default controller in routes.php, which produced the page as expected. However, if it means I have to change all the URLs to include the controller with an uppercase first letter this is less than ideal.

Notes

  • The site is running on PHP 5.3.17 FastCGI.
  • The index.php has been removed from the URL with an .htaccess rule of:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Any help is most appreciated.

Edit 1

I have narrowed it down to the _validate_request function in the core Router. It works if I comment out the call to that function from _set_request.

Edit 2

If I change the name of the _validate_request function to _validate_request2 and call it using the new name, it works perfectly. Is this function name a reserved word?

¿Fue útil?

Solución

Solved in the comments, writing this just to make it official ...

When upgrading, you have to always check if you have extensions of the core CodeIgniter libraries. If so, chances are that you are overloading at least parts of them and that could break the application when the original code is changed.

Otros consejos

In case anybody need , this one worked great for me:

for f in *php ; do mv "$f" "$(\sed 's/.*/\u&/' <<< "$f")" ; done

Codeigniter 3.x is now requesting that all libraries/controllers/models will have Uppercase filenames (first letter). So I wrote this small bash script - Searching for all *php file in the current directory , and replace the first character of each filename to capital letter:

e.g: test.php => Test.php

In my website, I faced the same problem. So I named all controller files in Uppercase like Home.php and all methods in Lowercase like index(). Then in URI request: I typed in each <a href=""> as the controller named inside. like ComingSoon.php:

class ComingSoon extends CI_Controller {}

HTML:

<a href="ComingSoon/index">

BUT Be Careful for something is very important:

when you include a view: you MUST type the view name as it named EXACTLY, like I did: I created a folder for every controller in lowercase like: /application/views/comingsoon/view.php

PHP View Include must look like:
$this->load->view("comingsoon/view.php");

The Folder is optional for you, but the view name must be exactly the same.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top