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
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
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.
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
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);