【问题标题】:CI Controller Method Calling issueCI 控制器方法调用问题
【发布时间】:2017-11-11 13:18:22
【问题描述】:

我在函数调用中遇到了一个奇怪的 Codeigniter 问题。我创建了一个控制器名称ErrorLog,然后创建了一个方法addUpdateError。然后在视图部分我创建了一个这样的链接(锚标记)

<a style="float:right" href="<?php echo site_url('errorLog/addUpdateError') ?>" title="Add an Error" alt="Add an Error">Add an Error</a>

我什至试试这个

<a style="float:right" href="errorLog/addUpdateError" title="Add an Error" alt="Add an Error">Add an Error</a>

这个也是

<a style="float:right" href="<?php echo base_url(); ?>errorLog/addUpdateError" title="Add an Error" alt="Add an Error">Add an Error</a>

浏览器中的网址是http://localhost/projectName/errorLog/addUpdateError,我认为它是有效的。

当我点击这个锚标记时,它给了我这个错误

默认控制器正在正确加载,但之后如果我导航到它无法正常工作的任何地方。我在 config.php 中正确设置了我的 base_url,并且我还将 index_page 设置为空白。我已经尝试了所有可能的方法并在谷歌上搜索。 我什至尝试在 Welcome controller 中使用 CodeIgniter-2.2.6 使用 Codeigniter 全新设置,但问题仍然存在。

目前我正在使用 PHP 7 和 COdeigniter 3 和 Ubuntu 16.04 我只是猜测这个问题可能是因为 PHP 7

任何帮助将不胜感激。

【问题讨论】:

  • 您是否已将 DB 驱动程序从 mysql 更新为 mysqli
  • 是的,我做到了,但我现在没有执行数据库操作,只是简单的点击就会导致问题。
  • 尝试使用 index.php 可能是 .htacess 不起作用。试试这个网址:- localhost/projectName/index.php/errorLog/addUpdateError
  • @Bhavin 谢谢好友,到目前为止它正在工作,但是如果我想从 URL 中删除 index.php 怎么办。可能问题可能会再次出现。
  • 您必须更改 .htaccess 文件才能从 url 中删除 index.php 文件。

标签: php codeigniter routing php-7


【解决方案1】:

您的问题是由于 .htaccess 文件造成的。

尝试以下步骤,

像这样设置配置文件(application/config/config.php),

$config['index_page'] = '';

之后,使用以下代码更改位于项目根文件夹而不是应用程序文件夹中的 .htaccess 文件。

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

【讨论】:

  • 感谢它的工作。我也尝试了相同的模式,但不知道发生了什么可能是我的 htaccess 文件中存在问题。
  • 是的,有时会发生。快乐编码。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-10
  • 1970-01-01
  • 2018-12-15
相关资源
最近更新 更多