PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 30, 2022

[FIXED] How do I use underscores and lowercase letters in URLs in Codeigniter 3?

 January 30, 2022     codeigniter, codeigniter-3, php-5.6, twig     No comments   

Issue

I am annoyed with encountering mysterious problem. My development environment has been created with the following directory structure.

document_root
 └ project
  ├ application
  │├ controllers
  ││└ admin
  ││ ├ Users.php
  ││ ├ Facility_Categories.php
  ││ └ Facilities.php
  │└ views
  │ └ admin
  │  ├ users
  │  │└ index.twig
  │  ├ facility_categories
  │  │└ index.twig
  │  └ facilities
  │   └ index.twig
  └ public
   └ index.php

In the development environment, these URLs appeared as expected.

https://www.example.com/project/admin/users/
 -> load admin/Users.php index function
https://www.example.com/project/admin/facilities/
 -> load admin/Facilities.php index function
https://www.example.com/project/admin/facility_categories/
 -> load admin/Facility_Categories.php index function

Recently, when I upload these files to a test environment. URL were not displayed correctly that contained "underscore". It looks like controller is not loaded.

https://www.example.com/project/admin/users/
 -> load admin/Users.php index function
https://www.example.com/project/admin/facilities/
 -> load admin/Facilities.php index function
https://www.example.com/project/admin/facility_categories/
 -> 404 Page Not Found (display codeigniter show_404 function)

By the way, if the URL is capitalized, the controller will load but View will not. (view is also displayed if view's direcotry name is capitalized.)

https://www.example.com/project/admin/Facility_Categories/
 -> 500 Internal Server Error
      (Twig\Error\LoaderError : Unable to find template "admin/Facility_Categories/index.twig")

I want to access with lower case URL. How can I solve the problem?


Solution

I solved this problem on my own to read following url

CodeIgniter Controller Case-Sensitive

CodeIgniter3 seemed to have to capitalize only the first letter of the controller name and all lowercase after that. (OK: Facility_categories.php NG: Facility_Categories.php)

I just changed 2 points.

  1. Change Controller File Name From Facility_Categories.php To Facility_categories.php
  2. Change Controller Class Name From class Facility_Categories To class Facility_categories

Now I can access to url that contain lowercase and underscores

https://www.example.com/project/admin/facility_categories/


Answered By - qwe001
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing