1

我不知道我做错了什么,但我只是有点乱

我有一个 aa href 那就是调用控制器

<a href="<?php echo base_url();?>mailing/index/?club=<?php echo $club_info[0]['club_title'];?>"><img src="<?php echo base_url();?>assets/front_assets/images/button_joinclub.png" width="180" height="44" border="0"></a>

现在的功能是这样的

class mailing extends CI_Controller{
    private $pagesize = 20;
    function __construct() {
        parent::__construct();
        @session_start();
    }

    function index()
    {
         echo $_REQUEST['club'];
    }
}

但它给了我错误

A PHP Error was encountered

Severity: Notice

Message: Undefined index: club

Filename: controllers/mailing.php

Line Number:12




EDIT

我需要从不同的页面调用邮件/索引,有时我需要传递参数,有时不需要

如果我使用

function index($club)
{
//function body;
}

然后我总是需要发送一些参数

有时调用href也可以是这样的

<a href="<?php echo base_url();?>mailing"><img src="<?php echo base_url();?>assets/front_assets/images/button_joinclub.png" width="180" height="44" border="0"></a>

所以它会要求一个错误,因为在函数定义中我已经发出了参数的存在,并且我没有通过这个链接传递任何参数

所以这就是我需要的原因

a href="<?php echo base_url();?>mailing/index/?club="<?php echo $club_info[0]['club_title'];?>"

这样我就可以使用 isset($_REQUEST['club'] 检查是否存在。

4

4 回答 4

1

首先,不需要 echo base_url(); 只有 /mailing/index 就足够了。要传递参数,您可以按照 McGarnagle 作为第三部分告诉您的方式进行。

<a href="/mailing/index/club_title"></a>

然后在您的控制器中的索引函数中:

$club_title = $this->uri->segment(3);

您刚刚设置了一个名为 club_title 的新变量来保存它的值。这就是您传递参数的方式,如果您不想从其他页面传递它,则不需要。这只意味着在这种情况下变量将为空。

URI 助手的工作方式让您了解发生了什么:

控制器 - 段 1 方法 - 段 2 参数 - 段 3

您可以根据需要添加任意数量的参数,然后使用 URI 调用访问它们。确保将其加载到配置文件夹中的 autoload.php 或每个控制器的构造函数中,如下所示:

$this->load->helper('url');

PS:我们从不在 codeigniter 中使用 $_REQUEST。

于 2013-07-12T03:16:30.190 回答
1

CodeIgniter 禁用所有 GLOBALS,除了$_GET,$_COOKIE$_POST确保安全。

参考:

Register_globals

During system initialization all global variables are unset, except those found in the $_GET, $_POST, and $_COOKIE arrays. The unsetting routine is effectively the same as register_globals = off.

请参阅此处的文档

于 2013-10-03T06:20:51.383 回答
1

CodeIgniter 带有帮助方法,可让您获取 POST、GET、COOKIE 或 SERVER 项目,但 CodeIgniter 禁用除 $_GET、$_COOKIE 和 $_POST 之外的所有 GLOBALS 以确保安全。

您可以使用以下输入法:

$this->input->post()

$this->input->get()

$this->input->cookie()

$this->input->server()

于 2020-02-24T06:04:57.157 回答
0

CodeIgniter出于安全原因清除变量。$_REQUEST我认为它与 Codeigniter Manual here中描述的自动输入过滤有关,但也没有具体提及。我不确定是否设置

$config['global_xss_filtering'] = TRUE;

在 config.php 中是否影响它。

于 2016-06-30T07:24:03.967 回答