【问题标题】:CodeIgniter in Ubuntu 16.04Ubuntu 16.04 中的 CodeIgniter
【发布时间】:2018-11-09 14:11:24
【问题描述】:

我正在尝试将我的 CI 项目从 Windows 中的本地主机移动到 Ubuntu。我正在与:

在我的 cognfig.php 中

$config['base_url'] = '';

$config['index_page'] = 'index.php';

我的虚拟主机:

<VirtualHost *:80>

  # Admin email, Server Name (domain name) and any aliases
  ServerAdmin mymail@mymail.com
  ServerName  mywebiml.com
  ServerAlias www.mywebiml.com


  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.php
  DocumentRoot /var/www/html/CLASE

</VirtualHost>

CI 应用程序的根文件夹是“CLASE”。 另外,我在 /etc/hosts 中添加了条目

MyIp   mywebiml.com
MyIp   www.mywebiml.com

问题是,当我尝试访问我的页面时,我不断收到来自 CI 的自定义 404 错误。

【问题讨论】:

  • 您是否使用a2ensite 启用了您的网站?
  • 是的。它必须与 CI conf 有关,因为我得到了 codeIgniter 的自定义 404 错误。

标签: codeigniter ubuntu virtualhost


【解决方案1】:

首先你必须给$config['base_url'] 一个值。使用以下

$config['base_url'] = 'http://mywebiml.com/';

其次,确保您使用的是 CI 所需的文件和类命名方案。类文件必须以类似 Ucfirst 的方式命名,而任何其他文件名(配置、视图、通用脚本等)都应全部小写。

不好:

some_class.php

好:

Some_class.php

类名应始终以大写字母开头。多个单词应该用下划线分隔,而不是 CamelCased。

不好:

class someClass {

好:

class Some_class {

文件名和类名必须完全相同 - 区分大小写。

上述规则在基于 Windows 的开发环境中无关紧要,但在像 Ubuntu 这样的 linux 系统上则适用。

如果您使用 .htaccess 重写 URL,以便删除 index.php,请使用以下内容。

$config['index_page'] = '';

【讨论】:

  • 谢谢!在类中将小写更改为大写!
猜你喜欢
  • 1970-01-01
  • 2018-07-30
  • 1970-01-01
  • 1970-01-01
  • 2016-11-26
  • 1970-01-01
  • 1970-01-01
  • 2017-01-13
  • 1970-01-01
相关资源
最近更新 更多