Codeigniter get value from url

How can I get value in controller from following url in codeigniter

http://localhost/directory/c_service/get_radius/lang=123

      

controller:

class C_service extends CI_Controller {
function __construct()
{
parent::__construct();
}

public function get_radius()
{

i need to get the vLUE 123 here
like,
`$value=$get['lang'];`

}

      

thank

+3


source to share


4 answers


In Codeigniter, you can simply do

public function get_radius($lang)
{
   var_dump($lang); //will output "lang=123"
}

      

This way your link can be simplified to http://localhost/directory/c_service/get_radius/123

if you don't want to do something like explode('=', $lang)

to get your value.



You should also consider adding a default value public function get_radius($lang=0)

if the link is opened without a parameter.

Adding more variables is as easy as public function get_radius($lang, $other)

forhttp://localhost/directory/c_service/get_radius/123/other

+6


source


You can use:

<?php
$this->input->get('lang', TRUE);
?>

      



TRUE Enable the XSS filtering you want to enable.

For more information see http://ellislab.com/codeigniter/user-guide/libraries/input.html .

+14


source


enable url helper in config / autoload.php

$autoload['helper'] = array('url');

      

or load the url helper in the desired controller or its method

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

      

and then use below in your controller

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

      

the above line will give you the first parameter, increasing the value you will get the parameters

$this->uri->segment(4);

      

you get the second, etc.

hope this helps you

+9


source


I manage it and I check that it works first load url

$this->load->helper('url');
$this->uri->segment(3);

      

example: http: // localhost / schoolmanagement / student / studentviewlist / 541

if you use $this->uri->segment(3);

you get (541) id

In the above line, you will get the first parameter, increasing the value, you will get the parameters

$this->uri->segment(4);

      

+2


source







All Articles