3

How can i recieve the value in a controller from the 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'];`

}

Thanks

2
  • what is your controller name? and What value do you intend to receive? Commented Mar 12, 2012 at 11:49
  • sorry,my controller name is "c_service" and "get_radius" is a function in controller..i need to recieve the value 123 inside the function "get_radius" Commented Mar 12, 2012 at 11:53

4 Answers 4

16

You can use:

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

The TRUE is to turn on XSS filtering, which you do want turned on.

Check out https://www.codeigniter.com/user_guide/libraries/input.html for more info.

Sign up to request clarification or add additional context in comments.

1 Comment

activate XSS is useful only when you want to display the value in the user browser. Otherwise it's useless, that's the reason why by default it's not activated.
8

enable url helper in config/autoload.php

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

or load url helper in desired controller or its method

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

and then use below in controller

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

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

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

will get you second and so on.

hope this helps you

Comments

7

In Codeigniter you can simply do

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

So your link could 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 however 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) for http://localhost/directory/c_service/get_radius/123/other

Comments

2

I manage it and i check it thats working first load the 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

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.