简体   繁体   English

如何在Codeigniter 3中的URL中使用下划线和小写字母?

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

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. 在开发环境中,这些URL按预期显示。

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". URL未正确显示包含“下划线”。 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. 顺便说一句,如果URL大写,控制器将加载但View不会。 (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. 我希望使用小写URL访问。 How can I solve the problem? 我该如何解决这个问题?

I solved this problem on my own to read following url 我自己解决了这个问题,以便阅读以下网址

CodeIgniter Controller Case-Sensitive CodeIgniter控制器区分大小写

CodeIgniter3 seemed to have to capitalize only the first letter of the controller name and all lowercase after that. CodeIgniter3似乎只需将控制器名称的第一个字母大写,之后全部小写。 (OK: Facility_categories.php NG: Facility_Categories.php ) (好的: Facility_categories.php NG: Facility_Categories.php

I just changed 2 points. 我刚换了2分。

  1. Change Controller File Name From Facility_Categories.php To Facility_categories.php 将控制器文件名从Facility_Categories.php更改为Facility_categories.php
  2. Change Controller Class Name From class Facility_Categories To class Facility_categories 更改控制器类名称从class Facility_Categoriesclass Facility_categories

Now I can access to url that contain lowercase and underscores 现在我可以访问包含小写和下划线的url

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM