Enabling $_Get in Codeigniter

Enabling $_GET in codeigniter

Add the following library to your application libraries. It overrides the behaviour of the default Input library of clearing the $_GET array. It allows for a mixture of URI segments and query string.

application/libraries/MY_Input.php

class MY_Input extends CI_Input 
{
function _sanitize_globals()
{
$this->allow_get_array = TRUE;
parent::_sanitize_globals();
}
}

Its also necessary to modify some configuration settings. The uri_protocol setting needs to be changed to PATH_INFO and the '?' character needs to be added to the list of allowed characters in the URI.

application/config/config.php

$config['uri_protocol'] = "PATH_INFO";
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?';

It is then possible to access values passed in through the query string.

$this->input->get('x');

How to use $_GET in Codeigniter

You're not passing $id to your get_current_entry() function.

In your controller, pass $id to your model like so:

$data['get_current_entry'] = $this->inner_query->get_current_entry($id);

Modify your model's get_current_entry() function to accept $id as a parameter:

function get_current_entry($id){
// other code here...
}

CodeIgniter Enabling Query Strings

Query strings in 1.7.2 are a joke, it uses ?c=controller&m=method to basically change your pretty urls to psuedo $_GET params. I really can't see why anyone would use it the way it's intended, it's very misleading and is not the same as normal query strings.

I highly suggest you check out the latest version of Codeigniter, where they do not unset the $_GET array (normal query strings are now usable). In one of the core files in the older versions it says CI does not use $_GET so we are going to unset() the global $_GET array. Well, what if I need to use $GET? I always thought it was crazy, and people have been screaming for true $_GET support for forever.

Seriously though, it's time to upgrade:

Latest: https://bitbucket.org/ellislab/codeigniter-reactor/

Stable: http://codeigniter.com/

how to retrieve HTTP $_GET values with CodeIgniter

$this->input->get() or $this->input->get_post()

Having Problem with $_get in Codeigniter

The usage of $_GET is discouraged in CI.

The simpliest way to rewrite that files is not using $_GET. Just add method='post' to your forms and tell your ajax requests to use post, if you have any. Use $_POST in PHP instead of $_GET.

If you are absolutely sure you need get requests passing parameters, you have to enable query strings. You can do it in your CI's config file:

$config['enable_query_strings'] = TRUE;

See section 'Enabling query strings' for details. But enabling query strings will cause Url helper and other helpers that generate URLs to malfunction.

So my suggestion is to use POST requests.

UPDATE Replace

<a href="studentprofile.php?studentid=<? echo $studentid?>"><? echo $studentname ?></a>

With

<a href="studentprofile.php?studentid=<? echo site_url("yourcontroller/studentprofile/$studentid")?>"><? echo $studentname ?></a>

Create method studentprofile:

<?php
class Yourcontroller extends CI_Controller {

public function studentprofile($id)
{
include("connect.php");
$number = $id;

$qP = "SELECT * FROM student WHERE studentid = '$number' ";
$rsP = mysql_query($qP);
$row = mysql_fetch_array($rsP);
extract($row);
$studentid = trim($studentid);
$studentname = trim($studentname);
$studentgender = trim($studentgender);
// and so on...
}
}
?>

$_GET does not work in Codeigniter 2.1.3

This line will parse the URL and populate the $_GET array with the URL's parameters:

parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);

It can then be accessed as you would normally access an array, for example:

$ref = $_GET['ref'];

You config - application/config/config.php - should be set as follows:

$config['uri_protocol'] = "PATH_INFO";

GET parameters in the URL with CodeIgniter

When I first started working with CodeIgniter, not using GET really threw me off as well. But then I realized that you can simulate GET parameters by manipulating the URI using the built-in URI Class. It's fantastic and it makes your URLs look better.

Or if you really need GETs working you can put this into your controller:

parse_str($_SERVER['QUERY_STRING'], $_GET); 

Which will put the variables back into the GET array.



Related Topics



Leave a reply



Submit