1

i dont know what am i doing wrong but i am just messed a bit

i have a a href thats calling a controller

<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>

now the function is this

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

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

but it gives me error

A PHP Error was encountered

Severity: Notice

Message: Undefined index: club

Filename: controllers/mailing.php

Line Number:12




EDIT

i need to call the mailing/index from different pages, and sometimes i need to pass parameter and sometimes not

if i use

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

then i always need to send some parameter

sometimes the calling href can be like this also

<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>

so it will call for an error since in function definition i have issued the presense of a parameter, and i am not passing any parameter through this link

so thats why i need

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

so that i can use isset($_REQUEST['club'] to check if present or not.

Saswat
  • 12,320
  • 16
  • 77
  • 156

4 Answers4

1

First of all, there is no need to echo base_url(); Only /mailing/index is enough. To pass parameters you do as McGarnagle told you as third segment.

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

Then in your controller in index function:

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

You have just set a new variable called club_title that holds its value. That's how you pass params and if you dont want to pass it from other pages, you don't need to. It only means that the variable will be null in that case.

The way URI helper works so you understand what happened:

Controller - segment 1 Method - segment 2 Paramater - segment 3

You can add as many parameters as you want and then call access them with URI. Make sure you load it in your autoload.php in config folder or in construct function of your each controller like this:

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

PS: We never use $_REQUEST in codeigniter.

SasaT
  • 731
  • 6
  • 19
1

CodeIgniter disables all GLOBALS except $_GET, $_COOKIE and $_POST to ensure security.

Reference:

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.

See Documentation here

Pupil
  • 23,834
  • 6
  • 44
  • 66
  • Is there a way to turn this of? It breaks the Facebook PHP SDK: http://stackoverflow.com/questions/6790272/why-is-facebook-php-sdk-getuser-always-returning-0/13278198#13278198 – Mischa Apr 03 '15 at 04:08
  • @Mischa, I would recommend not to break the in built standards as it is concerned about security. You can try other ways to get your code working. – Pupil Apr 06 '15 at 04:34
1

CodeIgniter comes with helper methods that let you fetch POST, GET, COOKIE or SERVER items , but CodeIgniter disables all GLOBALS except $_GET, $_COOKIE and $_POST to ensure security.

You can use input methods are as follow :

$this->input->post()

$this->input->get()

$this->input->cookie()

$this->input->server()

Community
  • 1
  • 1
Govinda Yadav
  • 539
  • 4
  • 14
0

CodeIgniter purges the $_REQUEST variable for security reasons. I assume it's related to the automatic input filtering described in the Codeigniter Manual here, but it's not specifically mentioned there either though. I am unsure whether setting

$config['global_xss_filtering'] = TRUE;

in config.php affects it or not.

vidhi
  • 104
  • 11